Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
621 views
in Technique[技术] by (71.8m points)

iphone - 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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

self.navigationItem.backBarButtonItem is for the back button that appears on the view pushed by the view controller. So you need to move that line to the previous view controller.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...