Swift can't show back button after hiding it

元气小坏坏 提交于 2020-01-24 17:04:45

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!