0

I want to get rid of the title on a navigation bar's back button. It keeps crowding the title of my view controller.

How do I hide it using Swift 3?

This doesn't work:

self.navigationController?.navigationItem.backBarButtonItem?.title = nil
Charles Black
  • 143
  • 1
  • 2
  • 9

5 Answers5

1

Add either

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

or

self.navigationController?.navigationBar.backItem?.title = ""

to your prepare:forsegue: if you use storyboard or before navigating.

Lawliet
  • 3,438
  • 2
  • 17
  • 28
1

THIS WORKS:

I had to put:

self.navigationItem.title = ""

That's it. If anybody can explain why this works, and the other posted answers don't, that'd be great!

Charles Black
  • 143
  • 1
  • 2
  • 9
0

It works for me . . replace nil with "" (Swift 3)

 self.navigationController?.navigationItem.backBarButtonItem?.title = "" 
roy
  • 6,685
  • 3
  • 26
  • 39
0

Check this out:

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

More detail: https://stackoverflow.com/a/32284525/4935811

Sour LeangChhean
  • 7,089
  • 6
  • 37
  • 39
0

Lets say you have A ViewController pushes B ViewController. And you wan't to remove the back button title in ViewController B. Then You need to set the backBarButtonItem of the A ViewController. Something like this.

class AViewController: UIViewController {
    override func viewDidLoad() {
        super.viewDidLoad()

        self.navigationItem.backBarButtonItem = UIBarButtonItem(title:"", style:.plain, target:nil, action:nil)
    }
}
Bilal
  • 18,478
  • 8
  • 57
  • 72