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

当前返回按钮:

<返回

需要的后退按钮:

< 其他任何东西

这些都没有奏效:

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

当前回答

back按钮属于前一个视图控制器,而不是当前显示在屏幕上的那个。 要修改返回按钮,你应该在按之前更新它,在启动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
}

Swift 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
}

OR

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

其他回答

override func viewWillAppear(_ animated: Bool) {

    self.tabBarController?.navigationItem.title = "Notes"

    let sendButton = UIBarButtonItem(title: "New", style: .plain, target: self, action: #selector(goToNoteEditorViewController))

    self.tabBarController?.navigationItem.rightBarButtonItem = sendButton
}

func goToNoteEditorViewController(){
   // action what you want
}

希望能有所帮助!!3 #迅速

虽然这些答案解决了问题,但这可能是一些有用的

class MainNavigatioController: UINavigationController {

    override func pushViewController(_ viewController: UIViewController, animated: Bool) {
        // first
        let backItem = UIBarButtonItem()
        backItem.title = "رجوع"
        self.viewControllers.last?.navigationItem.backBarButtonItem = backItem
        // then
        super.pushViewController(viewController, animated: animated)

    }

}

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

1.

navigationItem.backButtonTitle = "Title Goes Here"

(5)迅速

  2.

 let backButton = UIBarButtonItem()

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

 

这适用于Swift 5:

self.navigationItem.backBarButtonItem?.title = ""

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

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

你可以把这3行代码放到ViewController中你想要改变返回按钮的标题。

在你的重载函数中viewDidLoad(){}。

let backButton = UIBarButtonItem()
backButton.title = "My Back Button Title"
self.navigationController?.navigationBar.topItem?.backBarButtonItem = backButton