0

I'm trying to set view controller back button to text only.
I tried

self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStylePlain target:nil action:nil];  

but it also adding the arrow image that I don't want.
how can I set only text?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Mario
  • 2,431
  • 6
  • 27
  • 34

4 Answers4

0

You need to add custom UIBarButtonItem embedded with the UIButton :

UIButton* someButton = [UIButton buttonWithType:UIButtonTypeCustom];
[someButton setFrame:frame];
[someButton setTitle: //......
[someButton addTarget:self action:@selector(backButtonAction:) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem* someBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:someButton];
[self.navigationItem setLeftBarButtonItem:someBarButtonItem];
Kumar KL
  • 15,315
  • 9
  • 38
  • 60
0

Try setting leftBarButtonItem on the displayed view controller (not the one that is below and whose backBarButtonItem the app would otherwise display) and handle its taps by calling popViewController: on the navigation controller (assuming that you are using it. If it's just a UINavigationBar without navigation controller, pop the navigation item from that UINavigationBar.

johnyu
  • 2,152
  • 1
  • 15
  • 33
0

use like this but add this into parent view controller not in the child

 self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"Details" style:UIBarButtonItemStyleBordered target:nil action:nil];
Gajendra Rawat
  • 3,673
  • 2
  • 19
  • 36
0

This code hides the back text and arrow ,

[self.navigationItem setHidesBackButton:YES animated:NO];
[self.navigationItem setBackBarButtonItem:nil];
Ramdhas
  • 1,765
  • 1
  • 18
  • 26