美文网首页
iOS - 返回到之前的某个VC

iOS - 返回到之前的某个VC

作者: HanZhiZzzzz | 来源:发表于2017-05-19 11:39 被阅读0次

    popToViewController用法

    方式一,不推荐

    [self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:2] animated:YES];
    

    方式二,推荐

    for (UIViewController *controller in self.navigationController.viewControllers) {
        if ([controller isKindOfClass:[你要跳转到的Controller class]]) {
            [self.navigationControllerpopToViewController:controller animated:YES];
        }
    }
    
    UIViewController *viewController = nil;
    
    for (LoginVC *tempVc in self.navigationController.viewControllers) {
    
             if ([tempVc isKindOfClass:[LoginVC class]]) {
    
                      viewController = tempVc;
    
                }
    
    }
    
    [self.navigationController popToViewController:viewController animated:YES];
    

    方式三,推荐 这种方式可以适合返回指定控制器并调用其方法(比如刷新)

    // 返回调用的控制器

     LLXXXcontroller *myControl = nil;
        for (int i = 0; i < self.navigationController.viewControllers.count; i++) {
            
            CustomViewController *cv = self.navigationController.viewControllers[i];
            if ([cv isKindOfClass:[LLXXXcontroller class]]) {
                
                myControl = (LLXXXcontroller *)cv;
                break;
            }
        }
    
        [self.navigationController popToViewController:myControl animated:YES];
        [myControl refreshData];
    

    参考:https://www.cnblogs.com/linZhenDDDD/p/7771147.html

    相关文章

      网友评论

          本文标题:iOS - 返回到之前的某个VC

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