有什么办法可以给导航栏的后退按钮添加补全功能吗?
Is there any way to add a completion function to the navigation bar's back button?
我想知道是否有任何方法可以在按下导航栏中的后退按钮以隐藏导航栏本身后添加处理程序或完成函数。
为此,您应该实现自定义后退按钮
override func viewDidLoad {
super.viewDidLoad()
self.navigationItem.hidesBackButton = true
let newBackButton = UIBarButtonItem(title: "Back", style: UIBarButtonItemStyle.Bordered, target: self, action: "back:")
self.navigationItem.leftBarButtonItem = newBackButton
}
func back(sender: UIBarButtonItem) {
// Perform your custom actions
// ...
// Go back to the previous ViewController
self.navigationController?.popViewControllerAnimated(true)
}
或者当您希望控制器消失时,只需在 viewWillDisappear
方法中编写您的代码
我想知道是否有任何方法可以在按下导航栏中的后退按钮以隐藏导航栏本身后添加处理程序或完成函数。
为此,您应该实现自定义后退按钮
override func viewDidLoad {
super.viewDidLoad()
self.navigationItem.hidesBackButton = true
let newBackButton = UIBarButtonItem(title: "Back", style: UIBarButtonItemStyle.Bordered, target: self, action: "back:")
self.navigationItem.leftBarButtonItem = newBackButton
}
func back(sender: UIBarButtonItem) {
// Perform your custom actions
// ...
// Go back to the previous ViewController
self.navigationController?.popViewControllerAnimated(true)
}
或者当您希望控制器消失时,只需在 viewWillDisappear
方法中编写您的代码