2017-09-16 138 views
0

我有3个视图控制器,并且最初的一个嵌入在导航控制器中。在我的第二个视图控制器上,我隐藏了导航栏,并且我有一个自定义后退按钮,我想用它返回上一页。设置栏按钮项目作为导航控制器上的后退按钮

这是我工具栏上的后退按钮。

@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.'

+0

简单地用这个替换这一行 - navigationController?.navigationBar.popItem(animated:true) - self.navigationController?.popViewController(animated:true)。你的代码将像魅力一样运行;) –

回答

1
@IBAction func exitEditor(_ sender: Any) { 
    self.navigationController?.popViewController(animated: true) 
} 

这是怎么弹出当前导航堆栈中的viewController。