我有 3 个 View Controller ,第一个嵌入在导航 Controller 中。在我的第二个 View Controller 上,我隐藏了导航栏,并且我有一个自定义后退按钮,我想用它返回到上一页。
这是我在工具栏上的后退按钮。
@IBOutlet var backButton: UIBarButtonItem!
这是后退按钮的功能
@IBAction func exitEditor(_ sender: Any) {
navigationController?.navigationBar.popItem(animated: true)
}
当我测试它时,我得到这个错误:
'NSInternalInconsistencyException', reason: 'Cannot call popNavigationItemAnimated: directly on a UINavigationBar managed by a controller.'
最佳答案
@IBAction func exitEditor(_ sender: Any) {
self.navigationController?.popViewController(animated: true)
}
这就是您从导航堆栈中弹出当前 viewController 的方式。
关于ios - 将条形按钮项目设置为导航 Controller 上的后退按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46256535/