iOS - 返回到之前的某个VC

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)