Swift 中如何判断是push 过来的页面 还是present过来的 页面

在 Swift 中,可以通过检查当前视图控制器的 presentingViewController 属性来判断是通过 push 过来的页面还是 present 过来的页面。

下面是一个示例代码,展示如何判断是通过 push 还是 present 过来的页面:

Swift 复制代码
if let presentingViewController = self.presentingViewController {
    // 通过 present 过来的页面
    self.dismiss(animated: true, completion: nil)
} else if let navigationController = self.navigationController {
    // 通过 push 过来的页面
    navigationController.popViewController(animated: true)
}
相关推荐
浅念-1 小时前
C++ :类和对象(4)
c语言·开发语言·c++·经验分享·笔记·学习·算法
lly2024061 小时前
Docker 安装 Python
开发语言
道法自然|~1 小时前
BugkuCTF栅栏密码解题记录(原理+C语言实现)
c语言·开发语言
CircleMouse2 小时前
springboot项目中使用Java 8的日期时间API
java·开发语言·spring boot·后端·spring
前端达人2 小时前
被JavaScript忽视的Web Animations API:为什么说它是前端动画的真正未来?
开发语言·前端·javascript·ecmascript
米羊1212 小时前
风险评估文档记录
开发语言·网络·php
摘星编程3 小时前
解锁Agent智能体的未来:五大实战策略彻底革新人机协作模式
java·开发语言
Aerkui3 小时前
Go 泛型(Generics)详解
开发语言·后端·golang
clive.li3 小时前
go-webmvc框架推荐
开发语言·后端·golang