如何删除后退按钮的文本。

当前返回按钮:

<返回

需要的后退按钮:

< 其他任何东西

这些都没有奏效:

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

当前回答

这适用于Swift 5:

self.navigationItem.backBarButtonItem?.title = ""

请注意,它将对下一个被推送的视图控制器有效,而不是当前显示的视图控制器,这就是为什么它非常令人困惑!

同样,检查故事板并选择前一个视图控制器的导航项,然后在后退按钮(检查器)中键入一些内容。

其他回答

下面的代码可以添加到视图控制器中,从你想要更改返回按钮文本的视图控制器中

斯威夫特5

self.navigationItem.backBarButtonItem = UIBarButtonItem(title: "", style: .plain, target: self, action: nil)

例如:-

ViewController1 ViewController2

假设我们想要更新回viewcontroller2的标题,我们从viewcontroller1推送viewcontroller2。

那么您可以使用以下代码:-

let vc2 = storyboard.instantiateViewController(withIdentifier: "ViewController2")
self.navigationItem.backBarButtonItem = UIBarButtonItem(title:  "your custom back button title", style: .plain, target: self, action: nil)
self.navigationController?.pushViewController(vc2, animated: true)

有两种不同的方法来植入那部分,  

1.

navigationItem.backButtonTitle = "Title Goes Here"

(5)迅速

  2.

 let backButton = UIBarButtonItem()

backButton。title = "标题在这里" self.navigationController .navigationBar.topItem ?。backBarButtonItem = backButton

 

这对我很管用。斯威夫特5

navigationItem.backButtonTitle = ""

这应该可以工作:

override func viewDidLoad() {
    super.viewDidLoad()

    var button = UIBarButtonItem(title: "YourTitle", style: UIBarButtonItemStyle.Bordered, target: self, action: "goBack")
    self.navigationItem.backBarButtonItem = button

}

func goBack()
{
    self.navigationController?.popViewControllerAnimated(true)
}

虽然不建议这样做,因为这实际上取代了backButton,它也删除了后退箭头和滑动手势。

Swift 4 -在按任何视图控制器之前配置后退按钮

// if you want to remove the text
navigationItem.backBarButtonItem = UIBarButtonItem()

// if you want to modify the text to "back"
navigationItem.backBarButtonItem = UIBarButtonItem(title: "back", style: .plain, target: nil, action: nil)