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

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

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

if let presentingViewController = self.presentingViewController {
    // 通过 present 过来的页面
    self.dismiss(animated: true, completion: nil)
} else if let navigationController = self.navigationController {
    // 通过 push 过来的页面
    navigationController.popViewController(animated: true)
}

你可能感兴趣的:(swift,开发语言,ios)