附上viewControllers属性文档@property(nonatomic, copy) NSArray *viewControllers Discussion The root view controller is at index 0 in the array, the back view controller is at index n-2, and the top controller is at index n-1, where n is the number of items in the array.Assigning a new array of view controllers to this property is equivalent to calling the setViewControllers:animated: method with the animated parameter set to NO.
self.navigationController.viewControllers属性
[self.navigationController popToViewController:vc animated:YES];和这个方法达到目的。如下例子:
[self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:2] animated:YES];
index的值是你指定要返回栈里的哪个vc.还有一个方法也能实现
[self.navigationController setViewControllers:array];
根据实际需要,重新设置array。
Discussion
The root view controller is at index 0 in the array, the back view controller is at index n-2, and the top controller is at index n-1, where n is the number of items in the array.Assigning a new array of view controllers to this property is equivalent to calling the setViewControllers:animated: method with the animated parameter set to NO.
试过这个,但是没弄出来,不知道怎么搞
需要你提供将要跳转到的控制器在控制器栈中的索引位置。通过self.navigationController.viewControllers 属性,可以得到所以已压入控制器栈中的控制器集合(返回的是一个NSArray)类型。那么你可以通过压栈的顺序找到你要跳转的控制器所在集合中的索引。通过这个索引位置就可以找到这个控制器,再结合popToViewController方法就可以实现你要效果。
还有一个办法,就是重置这个栈中的所有控制器 self.navigationController.viewControllers = .... ///重置后的控制器集合
你的回答很详细,但如7楼说的,你的这方法没办法解决我的问题。 [self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:2] animated:YES];这个只能跳回从第一个界面push过来的其中某个界面,而如果重新定义self.navigationController ,可以跳回我想要的界面,但是这个的结果就是联系人界面变成了消息界面。