在 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)
}