Search code examples
iphoneobjective-ccocoa-touchios4uinavigationcontroller

navigationItem.backBarButtonItem not working? Why is the previous menu still showing as the button?


Trying to customize my back button in a drilldown navigation controller.

On my one view controller I have an Add button where the code programatically generates a new UIViewController:

- (void)add:(id)sender 
{
    MyAddViewController *addController = [[MyAddViewController alloc] initWithNibName:@"MyAddViewController" bundle:nil];

    [self.navigationController pushViewController:addController animated:YES];

    [addController release];
}

This works and when I click the add button it drills down into the new view. Inside the viewDidLoad method of MyAddViewController.m I have:

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

But this isn't working. The back button in the navigation controller remains the title of the previous view's controller on the stack. It seems that line does nothing. Did I miss something?

Thanks


Solution

  • This will only work on each child after the viewController that has self.navigationItem.backBarButtonItem.