我有一个登录页面的导航 Controller ,登录成功后,我想关闭导航,这意味着一旦登录成功,用户将不允许返回登录页面。我试图创建另一个 Storyboard并执行 segue,但导航栏仍然存在,无论如何以编程方式或从 Storyboard中关闭导航栏?
我不希望“配对”按钮出现在此页面上。
最佳答案
我找到了解决方案!
我在 iOS 11 和 iOS 13 上测试过,运行良好:)
protocol CustomNavigationViewControllerDelegate {
func shouldPop() -> Bool
}
class CustomNavigationViewController: UINavigationController, UINavigationBarDelegate {
var backDelegate: CustomNavigationViewControllerDelegate?
func navigationBar(_ navigationBar: UINavigationBar, shouldPop item: UINavigationItem) -> Bool {
return backDelegate?.shouldPop() ?? true
}
}
class SecondViewController: UIViewController, CustomNavigationViewControllerDelegate {
override func viewDidLoad() {
super.viewDidLoad()
(self.navigationController as? CustomNavigationViewController)?.backDelegate = self
}
func shouldPop() -> Bool {
if (needToShowAlert) {
showExitAlert()
return false
} else {
return true
}
}
}
关于swift - 从导航 Controller 快速停止导航,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34987009/