I have a navigationController-based app. I want to change the title of the back button for the root view controller. I have tried the following code in the rootViewControlle
Maybe you don't wan't every pushed viewController from a viewController have a Cancel button than just set a leftBarButtonItem in the display viewController with a custom title
self.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"back", @"") style:UIBarButtonSystemItemCancel target:self action:@selector(popViewController)] autorelease];
- (void)popViewController {
[self.navigationController popViewControllerAnimated:YES];
}
This is the best solution for this, don't set the navigationitem title as usual as self.navigationitem.title. Put this code on the parent view didload
CGRect frame = CGRectMake(0, 0, 320, 44);
UILabel *label = [[[UILabel alloc] initWithFrame:frame] autorelease];
label.backgroundColor = [UIColor clearColor];
label.font = [UIFont boldSystemFontOfSize:20.0];
label.shadowColor = [UIColor colorWithWhite:0.0 alpha:0.5];
label.textAlignment = UITextAlignmentCenter;
label.textColor = [UIColor whiteColor];
self.navigationItem.titleView = label;
label.text = @"My Navigation Bar";
By setting the title as above the actual navigation title will be nil, so the backbarbutton title will automatically be "Back"