2017-09-16 137 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。