我正在添加一些子視圖到主視圖控制器。當我添加其中一個子視圖時,我創建了一個自定義後退按鈕,以便它將返回到主視圖控制器,而不是導航堆棧中的先前視圖控制器。我可以通過編程添加它,但似乎無法弄清楚如何刪除它。任何幫助是極大的讚賞!如何刪除自定義導航欄後退按鈕
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'應該做你想做的事。 – Caleb
正是我所需要的。如果您將此作爲答案提交,我會接受它。感謝您的幫助@Caleb – tahoecoop