[英]How to remove custom nav bar back button
我在主视图控制器中添加了一些子视图。 当我添加这些子视图之一时,我创建了一个自定义的后退按钮,以便它将返回到主视图控制器,而不是导航堆栈中的先前视图控制器。 我可以通过编程方式添加它,但似乎无法弄清楚如何删除它。 任何帮助是极大的赞赏!
func createCustomBackButton() {
self.navigationItem.hidesBackButton = true
let customFont = UIFont.systemFontOfSize(26.0)
UIBarButtonItem.appearance().setTitleTextAttributes([NSFontAttributeName: customFont], forState: UIControlState.Normal)
// customBackButton is a property I set for UIBarButtonItem
customBackButton = UIBarButtonItem(title: "<", style: .Plain, target: self, action: "back:")
self.navigationItem.leftBarButtonItem = customBackButton
}
func back(sender: UIBarButtonItem) {
UIView.animateWithDuration(0.3, animations: {
self.containerView.alpha = 0
}, completion: { finished in
self.view.sendSubviewToBack(self.containerView)
self.navigationItem.hidesBackButton = false
// what do I do on this line to get this to disappear or set to nil??
self.customBackButton = UIBarButtonItem(title: "", style: UIBarButtonItemStyle.z, target: self, action: nil)
// clears out prior view that was there to free up memory
for view in self.containerView.subviews {
view.removeFromSuperview()
}
})
}
使用self.navigationItem.leftBarButtonItem = nil
将把leftBarButtonItem
重置为默认值。
您应该使用轻松的顺序。 如果使用情节提要板,请将其从“目标视图控制器”拖到要从中展开的VC的横向共享按钮(退出按钮)上。 随心所欲命名,我们称其为“放松”
然后在同一个VC中调用:
self.performSegueWithIdentifier("unwind", sender: self)
在VC中您想退回到:
@IBAction func unwindToMapSegue(segue: UIStoryboardSegue) {
// do something
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.