从堆栈中删除viewController和navigationItem

时间:2013-07-07 04:53:32

标签: objective-c ios6 uinavigationcontroller uinavigationbar

我有一个UINavigationController和我在当前的栈顶控制器中,我想打开一个新的控制器,然后删除当前的VC。简而言之,来自

[ViewController A]
[ViewController B]

[ViewController A]
[ViewController B]
[ViewController C]

[ViewController A]
[ViewController C]

我在VC B中通过以下方式完成此任务:

[self.navigationController pushViewController:VCC animated:YES];
[self removeFromParentViewController];

工作正常除了navigationItem堆栈仍然有来自VC B的标题/ backButton夹在A和C之间。

如何从UINavigationController堆栈中删除VC并且还更新navigationItem堆栈?

1 个答案:

答案 0 :(得分:3)

由于放置/移除视图控制器的“样式”,导航项目未显示。

在将newviewcontroller推送到导航控制器之前,先使用[self removeFromParentViewController]两次而不是[[self navigationController] popViewControllerAnimated:NO]

另一种方式是:

NSMutableArray *VCs = [self.navigationController.viewControllers mutableCopy];
[VCs removeObjectAtIndex:[VCs count] - 2];
self.navigationController.viewControllers = VCs;

看看这个:How do I pop the view controller underneath a pushed view controller?

试一试。

相关问题