2013-01-18 53 views
2

我有六个viewControllers。在viewController1我有一个button需要我到viewController6我怎样才能回到导航控制器

现在从viewController6我想分别弹出回viewController5viewController4viewController3viewController2viewController1

我该怎么做?

+0

您有2种使用导航控制器进行导航的方法。如果在[self.navigationController popToViewController: animated:BOOL]' 之前已经显示(推送)了控制器,或者您可以在控制器显示第一个时间的情况下“推送”控制器,则可以“弹出”[ ] self.navigationController pushViewController: animated:BOOL]' – Spire

回答

3

试试这个,

NSMutableArray *allViewControllers = [NSMutableArray arrayWithArray: self.navigationController.viewControllers]; 

插入您需要的视图控制器,以便使用

[allViewControllers insertObject:viewControllerX atIndex:requiredIndex]; 

如果你想只更换以前的viewController使用,

[allViewControllers replaceObjectAtIndex:indexRequired withObject:viewControlerX]; 

然后重新设置导航堆栈,

self.navigationController.viewControllers = allViewControllers; 

那么你可以使用以下弹出回任何的viewController:

[self.navigationController popViewControllerAnimated:YES]; 
+0

嗨Anusha,谢谢你的回复 – Ankita

+0

Anusha你已经解决了我的问题,非常感谢:) :) – Ankita

+0

@Ankita ok ... :) –

0

,如果你想弹出仅1 ViewController,或使用[self.navigationController popToRootViewControllerAnimated:YES];回到拳头ViewController

0

是的,这是可能的,你可以使用[self.navigationController popViewControllerAnimated:YES];

,如果你想从控制器栈中弹出1 ViewController

[self.navigationController popViewControllerAnimated:YES];

回到fist ViewController

[self.navigationController popToRootViewControllerAnimated:YES]; 

更多信息使用这个链接

http://developer.apple.com/library/ios/#documentation/uikit/reference/UINavigationController_Class/Reference/Reference.html

+0

嗨迪克西特,感谢您的答复。但我认为你没有得到我的问题。首先,我想从VC1使用按钮单击VC6,然后从VC6我想要移回到VC5,VC4,VC3,VC2和VC1。 – Ankita

0

使用

popToViewController:animated
setViewControllers:animated

0

用[self.navigationController pushViewController:]按照该顺序 : 从ViewController1,6,5,4,3,2

,并用[self.navigationController popToRootViewControllerAnimated:]从ViewController2去1.