0

I am trying to remove the title of the backBarButtonItem which has the title of the previous ViewController. This is what I am getting now.

enter image description here

I am trying to make it like this.

enter image description here

Eric Aya
  • 69,473
  • 35
  • 181
  • 253
Rezwan
  • 477
  • 5
  • 19
  • 2
    Possible duplicate of [How to set backButton text to empty?](https://stackoverflow.com/questions/34288419/how-to-set-backbutton-text-to-empty) – PPL Jun 05 '18 at 08:46
  • 3
    Possible duplicate of [UINavigationBar Hide back Button Text](https://stackoverflow.com/questions/23853617/uinavigationbar-hide-back-button-text) – CodeChanger Jun 05 '18 at 08:46
  • are you using Storyboard? – iamVishal16 Jun 05 '18 at 08:49

2 Answers2

1

From your First viewController call:

self.navigationItem.backBarButtonItem = UIBarButtonItem(title:"", style: .plain, target: nil, action: nil)
LorenzOliveto
  • 7,796
  • 1
  • 20
  • 47
  • thank you very much. this works like a charm. not quite sure how though. could you please explain. – Rezwan Jun 05 '18 at 09:35
  • 1
    Yes, the backBarButtonItem property of the navigationItem is the button used to go back to the current viewController, so you have to set it in the first viewController in order to remove the title in the second. You can see the full doc here https://developer.apple.com/documentation/uikit/uinavigationitem/1624958-backbarbuttonitem – LorenzOliveto Jun 05 '18 at 10:05
0

This will work for you. You can try -

self.navigationItem.backBarButtonItem?.title = ""
Rashed
  • 2,349
  • 11
  • 26