1

我几乎可以肯定有一天我看到有一些属性可以设置一个较短的 viewController 名称,以便在它推动另一个 viewController 并成为后退 viewController 时显示在后退按钮中。有人可以提醒我这是什么属性吗?

4

4 回答 4

8
- (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;
}
于 2012-04-23T14:24:02.450 回答
0

self.navigationItem.title = @"短名称";

于 2012-04-23T14:21:34.247 回答
0

我很想知道“正确”的答案是什么。我个人更改了最后一个控制器的名称(如根),它有效。

-(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在所有方面都相同。

于 2012-04-23T14:21:46.417 回答
0

您需要backBarButtonItemnavigationItem您的父视图控制器中自定义。

于 2012-04-23T14:23:07.263 回答