简体   繁体   English

Swift 重命名后退导航项

[英]Swift renaming the back navigation item

I'm trying to edit the tile of the back item in the navigation controller.我正在尝试编辑导航 controller 中后面项目的磁贴。

I have this scene, Navigation Controller -> Table View Controller -> TableViewController .我有这个场景, Navigation Controller -> Table View Controller -> TableViewController

In the second TableViewController I want to rename the the back item from " xxxx " to " Back ".在第二个 TableViewController 中,我想将后面的项目从“ xxxx ”重命名为“ Back ”。

Is there a way to do via the StoryBoard , or should I do it programmatically ?有没有办法通过StoryBoard来完成,或者我应该以编程方式完成?

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()他们都在 viewDidLoad()

Yes , you can do that with StoryBoard . 是的 ,您可以使用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 . 选择NavgationItemTableViewController您已经嵌入NavgationController后,在Attribute Inspector设置Back Button与您在您的情况需要标题是Back

在此处输入图片说明

The backBarButtonItem works for the view controller that you are going back TO not the one you are going back FROM . backBarButtonItem适用于您要返回TO而不是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)
self.navigationController?.navigationBar.topItem?.backBarButtonItem?.title = "back"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM