2014-02-11 61 views
0

如何在不使用initWithRootViewController的情況下在UINavigationController之上顯示模態ViewController,只需將它添加到現有的navigationcontroller堆棧中?將ViewController添加到現有的UINavigation堆棧

我的代碼是:

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

編輯:我其實想的是做這樣的: 「VC1推VC2模式VC3」 比用 「poptoroot ......到VC1」。但initWithRootViewController(vc3)正在破壞它。

+0

目前的模式和添加到現有的導航控制器是互斥的。也許你正在尋找'[self.navigationController pushViewController:controller animated:YES];'?! –

+1

我不想使用推。代碼完美地工作在is。我真正想要做的就是像「vc1 push vc2 modal vc3」,而不是使用「poptoroot ... to vc1」。但initWithRootViewController(vc3)正在破壞它。 – user3295976

+0

嘗試呈現您的控制器,而不是navi – Johnykutty

回答

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. 

這將有所幫助。

相關問題