Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change uinavigationbar back button text

I am currently trying to change the back button text of a subview that is loaded of a tablecell touch. However even with the way I am trying to implement it it still shows the parents title in the back button.

I am trying to load a new value into the back button inside viewdidload method like so

UIBarButtonItem *myBarButtonItem = [[UIBarButtonItem alloc] init];
myBarButtonItem.title = @"Back";
self.navigationItem.backBarButtonItem = myBarButtonItem;
[myBarButtonItem release];

however its not working.

like image 579
C.Johns Avatar asked Aug 30 '11 01:08

C.Johns


People also ask

How do I customize the back button on my iPhone?

Turn on Back Tap Check that you have the latest version of iOS on your iPhone 8 or later. Go to Settings > Accessibility > Touch, and tap Back Tap. Tap Double Tap or Triple Tap and choose an action. Double or triple tap on the back of your iPhone to trigger the action you set.

How do I add a back button to my storyboard?

Storyboard. You can also set this in the Storyboard. Select UINavigationBar and select the Attributes Inspector tab. Then you can change those two images under Back and Back Mask attributes.

How do I hide items in navigation?

Go to your Navbar settings and find the navigation item you want to hide for a particular page. Click to edit and assign it a classname. You could assign it something like "hide-navigation-item."


2 Answers

You need to change self.navigationItem.backBarButtonItem from previous view, not current view (I know, it seems to be a little bit illogical). For example, in your table view you can do the following:

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self setTitle:@"My title"];
    UIBarButtonItem *boton = [[UIBarButtonItem alloc] initWithTitle:@"Custom back button text" style:UIBarButtonItemStyleBordered target:self action:@selector(mySelector:)];
    self.navigationItem.backBarButtonItem  = boton;
    [boton release];
}
like image 114
Juanjo Avatar answered Oct 05 '22 02:10

Juanjo


This is where the documentation is not so clear until you have read and re-read and play around with each settings.
To change the title of the default back button add this line in viewDidLoad()

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

If you want the button to be invisible - then set the value to @"" empty string.

like image 32
Hung Tran Avatar answered Oct 05 '22 02:10

Hung Tran