[英]Set bar button item as back button on navigation controller
I have 3 view controllers, and the initial one is embedded in a navigation controller. 我有3个视图控制器,最初的一个嵌入在导航控制器中。 On my second view controller, I hide the navigation bar, and I have a custom back button that I would like to use to go back to the previous page.
在第二个视图控制器上,我隐藏了导航栏,并且有一个自定义的后退按钮,我想用它返回上一页。
This is my back button on the toolbar. 这是我在工具栏上的后退按钮。
@IBOutlet var backButton: UIBarButtonItem!
This is the function for the back button 这是后退按钮的功能
@IBAction func exitEditor(_ sender: Any) {
navigationController?.navigationBar.popItem(animated: true)
}
When I test it out, I get this error: 当我进行测试时,出现以下错误:
'NSInternalInconsistencyException', reason: 'Cannot call popNavigationItemAnimated: directly on a UINavigationBar managed by a controller.'
“ NSInternalInconsistencyException”,原因:“无法直接在由控制器管理的UINavigationBar上调用popNavigationItemAnimated:”。
@IBAction func exitEditor(_ sender: Any) {
self.navigationController?.popViewController(animated: true)
}
This is how you pop the current viewController from navigation stack. 这是从导航堆栈中弹出当前viewController的方式。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.