[英]NavigationBar back button change text after popViewController
I have a UINavigationController
connected to a UITabBarCotnroller
. 我有一个
UINavigationController
连接到UITabBarCotnroller
。 When i push a ViewController
and in that class i write this code in their viewWillAppear
method 当我推送一个
ViewController
并在该类中时,我在其viewWillAppear
方法中编写此代码
self.navigationController?.navigationBarHidden = false
let yourBackImage = UIImage(named: "Back.png")
self.navigationController?.navigationBar.backIndicatorImage = yourBackImage
self.navigationController?.navigationBar.backIndicatorTransitionMaskImage = yourBackImage
self.navigationController!.navigationBar.backItem?.title = "";
By this code i am just setting a back button image with empty title. 通过此代码,我只是将后退按钮图像设置为空标题。 But when i push another screen over the current pushed screen and then tap back it again shows the title with text "Back" I am writing the above code in every view controller's
viewWillAppear
method which will be push. 但是,当我在当前按下的屏幕上按下另一个屏幕,然后再次点击它时,显示标题为“ Back”的标题,这是在每个将被按下的视图控制器的
viewWillAppear
方法中编写上述代码。
While I believe setting the backIndicatorImage
and backIndicatorTransitionMaskImage
will work in viewDidAppear()
, I found issues with setting the back text itself. 虽然我相信设置
backIndicatorImage
和backIndicatorTransitionMaskImage
可以在viewDidAppear()
,但我发现设置反向文本本身存在问题。 I always had to set the text with a new button, and even then, it worked better for me to do it from the transitioning controller (as that's the view they would go back to, so I didn't have to care where the user was transitioning from). 我总是必须用一个新的按钮来设置文本,即使那样,我也可以从过渡控制器上进行操作(因为这是他们可以回到的视图,所以我不必在乎用户在哪里)正在过渡)。
You can try using this in your viewWillAppear()
, but I'm using this in my prepare(for:, sender:)
function. 您可以在
viewWillAppear()
尝试使用它,但是我在我的prepare(for:, sender:)
函数中使用它。
let backItem = UIBarButtonItem()
backItem.title = "" // In my case, I was setting it here; you would blank it out
self.navigationItem.backBarButtonItem = backItem
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.