隐藏后,Swift无法显示后退按钮 [英] Swift can't show back button after hiding it
问题描述
我有一个带静态单元格的UITableViewController,它有一个自定义后退按钮。我使用代码隐藏了viewDidLoad中的后退按钮:
var cancelBtn = UIBarButtonItem(标题:取消,样式:UIBarButtonItemStyle。 Plain,target:self,action:closeSettings)
self.navigationItem.hidesBackButton = true
self.navigationItem.leftBarButtonItem = cancelBtn
如果我没有self.navigationItem.hidesBackButton = true行,则仍会显示后退按钮箭头。在代码中使用该行,后退按钮被隐藏,取消按钮正好显示我想要的方式。当我从单元格打开另一个视图控制器时,问题就出现了,后退按钮不存在。单击单元格时,我实例化视图控制器,并使用导航控制器推送视图控制器。我试图把
self.navigationItem.hidesBackButton = false
$在pushViewController()之前的代码中,p $ p>
。当我这样做时,我看到后退按钮出现,但是当导航控制器上按下新的视图控制器时,后退按钮消失。
我甚至试图将目标View Controller的viewDidLoad和viewDidAppear中的hidesBackButton = false行,但我无法显示后退按钮。任何人都可以帮我引导我朝着正确的方向前进吗?
解决方案您是否尝试过设置
self.navigationItem.hidesBackButton = false
atviewWillDisappear()
?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?
解决方案Did you try setting
self.navigationItem.hidesBackButton = false
atviewWillDisappear()
?这篇关于隐藏后,Swift无法显示后退按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!