当我从导航栏中按下返回按钮时,我尝试跳过一个ViewController

当我转到下一个VC时,需要这样做:

A -> B -> C

但是,当我想从C返回时,我希望显示A ViewController:
C -> A

我设法用下一个代码做到这一点:
    NSMutableArray *newControllers = [[NSMutableArray alloc]initWithArray:controllers];
    [newControllers removeObjectAtIndex:newControllers.count-2];
    self.navigationController.viewControllers = newControllers;

问题是显示的导航栏。当我从A ViewController获取View时,将显示B ViewController的导航栏。

有什么方法可以删除导航栏项,例如从层次结构中删除视图控制器?

最佳答案

UIViewController *vcPop = nil;
for (UIViewController *viewContrl in self.navigationController.viewControllers) {
   if ([viewContrl class] == [YOUR POP VIEW CONTROLLER class]) {
       vcPop = (YOUR POP VIEW CONTROLLER  *)viewContrl;
       break;
 }
}
if(vcPop)
   [self.navigationController popToViewController:vcPop animated:YES];

09-27 04:16