问题
I almost sure I saw someday that there is some property to set a shorter name of viewController to be display in the back button when it push another viewController and become the back viewController. Can some one remind me what is this property?
回答1:
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
// Custom initialization
self.title = @"First View Controller";
// this defines the back button leading BACK TO THIS controller
UIBarButtonItem *backBarButtonItem = [[UIBarButtonItem alloc]
initWithTitle:@"Back"
style:UIBarButtonItemStyleBordered
target:nil
action:nil];
self.navigationItem.backBarButtonItem = backBarButtonItem;
[backBarButtonItem release];
}
return self;
}
回答2:
self.navigationItem.title = @"short name";
回答3:
You need to customize the backBarButtonItem
from the navigationItem
in your parent view controller.
回答4:
I'm curious to see what the "right" answer is. Personally I change the name of the last controller (like the root), which works.
-(void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
[super navigationController:navigationController willShowViewController:viewController animated:animated];
UIViewController *root = [self.navigationController.viewControllers objectAtIndex:0];
if (something)
root.title = @"Apply";
else
root.title = "Root"
}
This works identically to self.navigationItem.title
in all regards.
来源:https://stackoverflow.com/questions/10282345/objective-c-how-to-display-a-shorter-name-of-viewcontroller-on-back-button