I set up my backbutton in the app delegate method ‘navigationController willShowViewController’ method. It is added as a leftbarButton for the viewcontroller in display as seen in the code below.
- (void)navigationController:(UINavigationController *)navigationController
willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
if (viewController != [navigationController.viewControllers objectAtIndex:0]) {
CustomNavButton *customBackButton = [[CustomNavButton alloc]initWithBackButtonAndFrame:CGRectMake(0, 0, 52, 33)];
customBackButton.navcon = navigationController;
UIBarButtonItem *newBackButton = [[UIBarButtonItem alloc]initWithCustomView:customBackButton];
viewController.navigationItem.leftBarButtonItem = newBackButton;
[newBackButton release];
viewController.navigationItem.hidesBackButton = YES;
}
}
I tried to overwrite the leftbar button in another view controller as seen below. But to no avail.
CustomNavButton *feedButton = [[CustomNavButton alloc]initWithTitle:@"Feed" andFrame:CGRectMake(0, 0, 50, 32)];
[feedButton.customNavButton addTarget:self action:@selector(showFeedPage) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *leftFeedButton = [[UIBarButtonItem alloc]initWithCustomView:feedButton];
qavc.navigationItem.leftBarButtonItem = leftFeedButton;
It seems like the appdelegate method always runs after the code in my viewcontroller and hence whatever changes to the left bar button in my viewcontroller will be replaced by the backbutton defined in the app delegate.
Is there anyway around this?
This is what I do in my app and it works fine: