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)
}
相关推荐
玄同76514 分钟前
我的 Trae Skill 实践|使用 UV 工具一键搭建 Python 项目开发环境
开发语言·人工智能·python·langchain·uv·trae·vibe coding
Yorlen_Zhang25 分钟前
Python Tkinter Text 控件完全指南:从基础编辑器到富文本应用
开发语言·python·c#
lxl130726 分钟前
C++算法(1)双指针
开发语言·c++
不绝19137 分钟前
C#进阶:预处理指令/反射,Gettype,Typeof/关键类
开发语言·c#
无小道43 分钟前
Qt-qrc机制简单介绍
开发语言·qt
zhooyu1 小时前
C++和OpenGL手搓3D游戏编程(20160207进展和效果)
开发语言·c++·游戏·3d·opengl
HAPPY酷1 小时前
C++ 和 Python 的“容器”对决:从万金油到核武器
开发语言·c++·python
大鹏说大话1 小时前
告别 MSBuild 脚本混乱:用 C# 和 Nuke 构建清晰、可维护的现代化构建系统
开发语言·c#
Mr_sun.1 小时前
Day09——入退管理-入住-2
android·java·开发语言
MAGICIAN...1 小时前
【java-软件设计原则】
java·开发语言