我试图阻止某些 ViewController 返回。我已将 UINavigationController 子类化以进行一些 UI 自定义。我使 UINavigationController 子类符合 UINavigationBarDelegate 协议(protocol)并尝试实现 navigationBar:shouldPop 方法。 我有这段代码:
func navigationBar(_ navigationBar: UINavigationBar, shouldPop item: UINavigationItem) -> Bool {
print("Popping: \(item.title)")
return true
}
当我使用从左侧滑动返回时,该方法被调用并且一切正常。当我按下后退按钮时,该方法仍会被调用,但 ViewController 不会弹出。如果 ViewController 是堆栈中的第二个,则后退按钮会消失,就像导航栏认为确实发生了弹出一样。谁能帮我理解这种行为?
最佳答案
您必须手动弹出 View :
func navigationBar(_ navigationBar: UINavigationBar, shouldPop item: UINavigationItem) -> Bool {
print("Popping: \(item.title)")
self.popViewController(animated: true)
return true
}
关于ios - UINavigationBarDelegate shouldPop 项目奇怪的行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42581851/