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
  • 307,833
  • 40
  • 508
  • 550
Mario
  • 2,331
  • 6
  • 25
  • 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,176
  • 9
  • 37
  • 59
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
  • 14
  • 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,613
  • 2
  • 18
  • 36
0

This code hides the back text and arrow ,

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