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)
}
相关推荐
不想写bug呀2 小时前
多线程案例——单例模式
java·开发语言·单例模式
我不会写代码njdjnssj3 小时前
网络编程 TCP UDP
java·开发语言·jvm
李少兄9 天前
解决OSS存储桶未创建导致的XML错误
xml·开发语言·python
阿蒙Amon9 天前
《C#图解教程 第5版》深度推荐
开发语言·c#
学Linux的语莫9 天前
python基础语法
开发语言·python
暖馒9 天前
C#委托与事件的区别
开发语言·c#
嘉琪0019 天前
2025——js 面试题
开发语言·javascript·ecmascript
Jinxiansen02119 天前
Vue3 中 ref 与 reactive 使用场景总结(含对比与示例)
开发语言·javascript·ecmascript
时空自由民.9 天前
C++ 不同线程之间传值
开发语言·c++·算法
止观止9 天前
Rust智能指针演进:从堆分配到零复制的内存管理艺术
开发语言·后端·rust