1

我有一个导航视图控制器 A,它通向控制器 B,然后是控制器 C。控制器 B 是一个登录屏幕,所以一旦用户登录,用户就会被带到控制器 C。我最初想做的是有后退按钮在控制器 C 上,将用户带回控制器 A(因为用户已经登录,所以没有必要让后退按钮将用户带回控制器 B,即登录屏幕)。我已经成功地做到了这一点,除了一个我似乎无法修复的特殊错误。从控制器 C 转换到控制器 A 时,控制器 A 的导航栏上会添加一个后退按钮!控制器 A 一开始就没有后杠,这让我快疯了!

我尝试在 viewWillAppear 方法中输入以下所有代码:

self.navigationItem.backBarButtonItem = nil;
self.navigationItem.hidesBackButton = YES;
[self.navigationItem setHidesBackButton:YES];

这些都没有带走后退按钮!我不知道该怎么做,任何建议/帮助将不胜感激我仍然是菜鸟。

4

1 回答 1

0

Don't put the popToRoot in the viewWillDisappear method. I assume that you have some function that gets called when the user is all done with the registration process in Controller C. At the end of that method you need to put [self.navigationController popToRootViewControllerAnimated:YES]

Putting it in viewWillDisappear and especially before the [super viewWillDissappear] method is most likely causing the problem.

EDIT:

Try structuring your viewWillDisappear method like this, with the super call first:

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];

    [self.navigationController popToRootViewControllerAnimated:YES];
}

EDIT:

Well, I have got it to kind of work. If you don't need to push anymore views onto it after you have popped from Controller C this will work. Update the -viewWillDisappear in Controller C to look like this:

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];

    [self.navigationController setViewControllers:@[[self.navigationController.viewControllers objectAtIndex:0]] animated:YES];
}
于 2013-07-24T00:49:10.180 回答