我几乎可以肯定,我看到有一天,有一些属性来设置的viewController的一个较短的名称是显示在后退按钮时,另一个推的viewController,并成为后面的viewController。 可有一个人提醒我这是什么性质?
Answer 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;
}
Answer 2:
self.navigationItem.title = @ “短名称”;
Answer 3:
您需要定制backBarButtonItem
从navigationItem
在父视图控制器。
Answer 4:
我很好奇,看看“正确”的答案是什么。 个人而言,我改变了最后一个控制器(如根),其作品的名称。
-(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"
}
这同样工作到self.navigationItem.title
在所有方面。
文章来源: Objective c - how to display a shorter name of viewController on back button