如何在navigation controller上弹出UiviewController,并同时推动Uiview



我在 UINavigationController上面临问题...

我有这个层次结构

UINavigationController
 |- root controller
 |- ViewController A

我在ViewController A中有一个按钮,然后按ViewController B,但是我想在添加ViewController B

之前删除ViewController A

因此,层次结构在过程之后要像这样

UINavigationController
 |- root controller
 |- ViewController B

它应该从ViewController A滑到ViewController B,但是如果您向后滑动,则返回root Controller

预先感谢您。

您应该使用uinavigation controller的setViewControllers方法,然后简单地将其添加为一个数组root and viewController b

//get the existing navigationController view stack
NSMutableArray* newViewControllers = [NSMutableArray arrayWithArray:self.navigationController.viewControllers];
//drop the last viewController and replace it with the new one!
ViewControllerB *childController = [[ViewControllerB alloc] initWithNibName:@"ViewControllerB" bundle:nil];
[newViewControllers replaceObjectAtIndex:newViewControllers.count-1 withObject:self];
//set the new view Controllers in the navigationController Stack
[self.navigationController setViewControllers:newViewControllers animated:YES];

可能会帮助您。

iPhone avaigation controller清除视图堆栈

这是解决问题的另一种方法。如果您有可用的视图控制器的实例,则可以随时弹出。

看看[UINavigationController setViewControllers:animated:]

[self.navigationController setViewControllers:@[rootViewController, viewControllerB] animated:YES];

这应该导致推动动画。

但是,老实说:如果您拥有这样的UI,您最喜欢首先不想使用NavigationController,因为这会使用户感到困惑。隐喻的UinavigationControllers的实施非常简单。您真的不想弄乱这一点。您可能想查看Apple Human Interface指南,然后选择另一种介绍您的视图的选项!

最好的方法是使用新的ViewController启动NavigationController,而不是同时删除和推动。

从viewcontroller a,

推送
[self.navigationController initWithRootViewController:ViewControllerB];

最新更新