3

enter image description here

I need empty back button title, so using category method as:

-(void)removeBackButtonTitle
{
    UIBarButtonItem *newBackButton =
    [[UIBarButtonItem alloc] initWithTitle:@""
                                     style:UIBarButtonItemStylePlain
                                    target:nil
                                    action:nil];
    [[self navigationItem] setBackBarButtonItem:newBackButton];
}

But I have a situation where I need to take Container View and some viewcontroller as child view controller and its view as a subview. Now upon navigation from this view, back button title is not setting to empty.

Ashish Kakkad
  • 23,586
  • 12
  • 103
  • 136
Preetam Jadakar
  • 4,479
  • 2
  • 28
  • 58

5 Answers5

4

Simply add the following code to your viewDidLoad/viewWillAppear..

self.navigationController.navigationBar.topItem.title = @"";

This will remove Back text from that Back button. Also here you can set your own title as you desire.


@preetam .. for your case, every view controller has its lifecycle methods viewDidLoad, viewWillAppear.

Also, you are using Default navigation bar/Custom NavigationBar as you shown in screenshot.

If you're using Default, then your answer is given above. otherwise, you can remove the Back text in Storyboard itself.

Hope it helps..

Balaji Ramakrishnan
  • 1,909
  • 11
  • 22
0

Try this code and set setTitle to blank @"":

[self.navigationItem.backBarButtonItem setTitle:@""]; //make Title for backBarbutton to blank

It works for you

0

You need to add following lines of code in the (previous) view controllers where you don't want to display back button title.

- (void)viewWillAppear:(BOOL)animated {
    self.title = @"Your Title";
}

- (void)viewWillDisappear:(BOOL)animated {
    self.title = @"";
}
Hima
  • 1,249
  • 1
  • 14
  • 18
0

For Swift 3 you can use this:

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
  let backItem = UIBarButtonItem()
  backItem.title = ""
  navigationItem.backBarButtonItem = backItem}
-1

Try below line of code.

UIBarButtonItem *newBackButton =
[[UIBarButtonItem alloc] initWithTitle:@""
                                 style:UIBarButtonItemStylePlain
                                target:nil
                                action:nil];

self.navigationItem.leftBarButtonItems =[[NSArray alloc] initWithObjects:newBackButton, nil];
self.navigationItem.leftItemsSupplementBackButton = YES;
Payal Maniyar
  • 4,293
  • 3
  • 25
  • 51