问题
I have a UITableViewController with static cell that has a custom back button. I hide the back button in viewDidLoad with the code:
var cancelBtn = UIBarButtonItem(title: "Cancel", style: UIBarButtonItemStyle.Plain, target: self, action: "closeSettings")
self.navigationItem.hidesBackButton = true
self.navigationItem.leftBarButtonItem = cancelBtn
If I don't have the self.navigationItem.hidesBackButton = true line in place, the back button arrow still appears. With that line in the code, the back button is hidden and the Cancel button appears exactly how I want. The problem is coming when I open another view controller from a cell, the back button is not present. I instantiate the view controller when a cell is clicked, and use the Navigation Controller to push the View Controller. I have attempted to put
self.navigationItem.hidesBackButton = false
in the code right before pushViewController(). When I do that I see the back button appear, but when the new View Controller is pushed on the Navigation Controller, the back button disappears.
I have even attempted putting the hidesBackButton = false line in the target View Controller's viewDidLoad and viewDidAppear, but I was not able to get the back button to appear. Could anyone help steer me in the right direction on what I could be doing wrong?
回答1:
Did you try setting self.navigationItem.hidesBackButton = false
at viewWillDisappear()
?
回答2:
Try this setting
self.navigationItem.hidesBackButton = false
on the destination view controller in the ViewWillAppear section.
来源:https://stackoverflow.com/questions/29394194/swift-cant-show-back-button-after-hiding-it