UINavigationController中“title”的问题

时间:2011-06-02 13:11:09

标签: iphone ios uinavigationcontroller uinavigationbar title

我遇到标题和UINavigationController问题。我在UIViewControllerCurrent使用以下代码,当我从NextViewController返回时,NavBar的标题仍然是“上一页”..任何人都可以帮助我解决这个问题吗?感谢。

[self setTitle:@"Previous"]; 
NextViewController *controller = [[NextViewController alloc] init]; 
[[self navigationController] pushViewController:controller animated:YES]; 
[controller release], controller = nil; 

- (void)viewWillAppear:(BOOL)animated; {     
[self setTitle:@"Real Title"];     
[super viewWillAppear:animated]; } 

3 个答案:

答案 0 :(得分:2)

我会尝试交换两行

[self setTitle:@"Real Title"];     
[super viewWillAppear:animated];

这样你就得到了

[super viewDidAppear:animated];
[self setTitle:@"Real Title"];

我会把这些放到viewDidAppear中。

答案 1 :(得分:0)

尝试使用下面的UINavigationController委托方法。

- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated;
- (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated;

使用其中一种委托方法更改标题。

答案 2 :(得分:0)

如果dasdoms解决方案无效,请尝试以下操作。

在弹出之前的NextViewController中运行此代码。

for (int i =0; i < [[self.navigationController viewControllers] count]; i++)
    {
        UIViewController *aController = [[self.navigationController viewControllers] objectAtIndex:i];

        if ([aController isKindOfClass:[PreviousViewController class]])
        {
            PreviousViewController *aPreviousViewController = (PreviousViewController *)aController;
            aPreviousViewController.title = @" Real Title";
        }

    }