【问题标题】:remove previous view controller from hierarchy从层次结构中删除前一个视图控制器
【发布时间】:2014-10-02 11:19:12
【问题描述】:

当我按下导航栏中的返回按钮时,我正在尝试跳过一个 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 的导航栏。

有什么方法可以像从层次结构中删除视图控制器一样删除导航栏项目?

【问题讨论】:

    标签: ios objective-c uiviewcontroller uinavigationcontroller uinavigationbar


    【解决方案1】:
    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];
    

    【讨论】:

    • 是的,这就是我要找的...非常感谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-11-24
    • 2012-10-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多