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];

 

人已赞赏
iOS文章

IQKeyboardManager失效

2019-11-12 13:43:16

iOS文章

UITableView多选删除,类似mail中的多选删除效果

2019-11-12 21:36:26

个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
有新消息 消息中心
搜索