Onichan Onichan - 1 year ago 108
Swift Question

How to set back button text

How do you remove the back button text in Swift?

current back button: <Back
desired back button: <AnythingElse

None of these have worked:

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

Answer Source

The back button belongs to the previous view controller, not the one currently presented on screen.
To modify the back button you should update it before pushing, on the view controller that initiated the 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
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download