一尘不染

如何在Swift中设置后退按钮文本

swift

如何删除后退按钮文本。

当前的后退按钮:

<返回

所需的后退按钮:

<其他

这些都不起作用:

self.navigationItem.backBarButtonItem?.title = "Back"
self.backItem?.title = ""
self.navigationController?.navigationBar.backItem?.title = ""
self.navigationItem.backBarButtonItem?.title = ""
self.navigationController?.navigationItem.backBarButtonItem?.title="Back"
self.navigationController?.navigationBar.backItem?.title = ""
self.navigationController?.navigationItem.backBarButtonItem?.title

阅读 224

收藏
2020-07-07

共1个答案

一尘不染

后退按钮属于上 一个 视图控制器,而不是当前在屏幕上显示的那个。
要修改后退按钮,您应该 启动segue的视图控制器上 按下按钮 之前 对其 进行 更新:

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    let backItem = UIBarButtonItem()
    backItem.title = "Something Else"
    navigationItem.backBarButtonItem = backItem // This will show in the next view controller being pushed
}

斯威夫特3、4和5:

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    let backItem = UIBarButtonItem()
    backItem.title = "Something Else"
    navigationItem.backBarButtonItem = backItem // This will show in the next view controller being pushed
}

要么

// in your viewDidLoad or viewWillAppear
navigationItem.backBarButtonItem = UIBarButtonItem(
    title: "Something Else", style: .plain, target: nil, action: nil)
2020-07-07