美文网首页
返回指定控制器

返回指定控制器

作者: 红姑娘 | 来源:发表于2016-09-07 15:17 被阅读27次


     

        // 返回跟控制器

         [self.navigationController popToRootViewControllerAnimated:YES];

     //     从导航push过去的视图想要返回指定控制器时可以使用以下方法

      //  第一种:

         //objectAtIndex后面的参数就是你想要返回的控制器在navigationController.viewControllers的下标

        [self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:0] animated:YES]

     //  第二种:  

       //UIViewController是指定的要返回的控制器

      for (UIViewController *controller in self.navigationController.viewControllers) {

       if ([controller isKindOfClass:[UIViewController class]]) {

       [self.navigationController popToViewController:controller animated:YES];   

       }

      }

       //切记:不可使用如下方法会导致崩溃

      UIViewController *VC = [[UIViewController alloc] init];

     [self.navigationController popToViewController:VC animated:YES];

   //  崩溃信息如下:

       //Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Tried to pop to a view controller that doesn't exist.'

相关文章

网友评论

      本文标题:返回指定控制器

      本文链接:https://www.haomeiwen.com/subject/ilofkttx.html