Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS >> UINavigation Item Back Button Title Doesn't Change

I'm trying to set the BACK button for a pushed VC set within a UINavigationController stack. I use the following code, and it's not working - I still get the previous VC name appearing as the back button title.

-(void)viewWillAppear:(BOOL)animated {

    [super viewWillAppear:animated];

    self.title = @"VC Title";

    UIBarButtonItem* myBackButton = [[UIBarButtonItem alloc]
                                     initWithTitle:@"Back"
                                     style:UIBarButtonItemStyleBordered
                                     target:nil
                                     action:nil];

    self.navigationItem.backBarButtonItem = myBackButton;

}

Anyone?

like image 467
Ohad Regev Avatar asked Aug 26 '13 13:08

Ohad Regev


People also ask

How can remove back button in iOS?

You can do: [self. navigationItem setHidesBackButton:YES]; In your second view controller (the one you want to hide the button in).

How to set the back button title of the navigation item?

The back button sort of belongs to the parent view controller. The Navigation Item gives you a handle to the back button, so you can set the title in code or in the Storyboard. If you leave the Navigation Item Back Button text as the default empty string, the back button title will become "Back". Other approaches work, why use this one?:

How are view controller titles synced with the navigation item titles?

By default the view controller title is synced with the navigation item title. @Rincewind you said: "The navigation menu titles come from the navigation item's back button title first on the assumption that clients who choose to override that title do so because it is a better title than the navigation item's title."

How to set destiny view controller back button title?

Let's supouse that you have a navigation controller going to ViewA from ViewB. In IB, select ViewA's navigation bar, you should see these options: Title, Prompt and Back Button. ViewA navigate bar options The trick is choose your destiny view controller back button title (ViewB) in the options of previous view controller (View A).

Is it possible to override the back button title on child view?

While it's possible to override the back button title on the child view controller, it was a challenge getting a handle to it until it had already flashed briefly on the screen. Some of the approaches construct a new back button and override the existing one. I'm sure it works, and probably necessary in some use cases.


1 Answers

in parent view controller:

- (void)viewWillDisappear:(BOOL)animated
{
    self.title = @"Back";
}

- (void)viewWillAppear:(BOOL)animated
{
    self.title = @"Title of your navigation bar";
}

Will do the trick

like image 115
Michal Gumny Avatar answered Nov 16 '22 01:11

Michal Gumny