将ViewController添加到现有UINavigation堆栈

时间:2014-02-11 07:09:19

标签: xcode uinavigationcontroller

如何在不使用initWithRootViewController的情况下在UINavigationController上呈现模态ViewController,只需将其添加到现有的navigationcontroller堆栈中即可?

我的代码是:

TableViewController *controller = [self.storyboard instantiateViewControllerWithIdentifier:@"TableView"];
UINavigationController *navi = [[UINavigationController alloc] initWithRootViewController:controller];
[self presentViewController:navi animated:NO completion:nil];

编辑:我真正想做的是:“vc1 push vc2 modal vc3”而不是使用“poptoroot ... to vc1”。但是initWithRootViewController(vc3)正在破坏它。

1 个答案:

答案 0 :(得分:1)

如果要更改navigationController的堆栈。使用:

- (void)setViewControllers:(NSArray *)viewControllers animated:(BOOL)animated NS_AVAILABLE_IOS(3_0); // If animated is YES, then simulate a push or pop depending on whether the new top view controller was previously in the stack.

这会有所帮助。