Swift renaming the back navigation item

故事扮演 提交于 2019-12-20 05:25:09

问题


I'm trying to edit the tile of the back item in the navigation controller.

I have this scene, Navigation Controller -> Table View Controller -> TableViewController.

In the second TableViewController I want to rename the the back item from "xxxx" to "Back".

Is there a way to do via the StoryBoard, or should I do it programmatically?

This is what I've tried but it does not work:

let backItem = UIBarButtonItem()
backItem.title = "Back"
navigationItem.backBarButtonItem? = backItem

or

navigationItem.backBarButtonItem?.title = "back"

both of them in the viewDidLoad()


回答1:


Yes, you can do that with StoryBoard. Select the NavgationItem in TableViewController that you have embedded in NavgationController after that in the Attribute Inspector set the Back Button with title that you want in your case it is Back.




回答2:


The backBarButtonItem works for the view controller that you are going back TO not the one you are going back FROM.

So, in your case in the first view controller you can have the code...

navigationItem.backBarButtonItem = UIBarButtonItem(title: "Some title", style: .done, target: nil, action: nil)


来源:https://stackoverflow.com/questions/42973078/swift-renaming-the-back-navigation-item

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