iOS-返回指定控制器

开发中会遇到在列表页面查看详情,之后编辑内容,编辑完成之后需要返回到列表页面,大概有两种实现方式:

    //索引
    NSInteger index = [[self.navigationController viewControllers] indexOfObject:self];
    if (index>2) {
        [self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:(index-2)] animated:YES];
    } else {
        [self.navigationController popToRootViewControllerAnimated:YES];
    }
    
    //类型判断
    for (UIViewController *controller in self.navigationController.viewControllers) {
        if ([controller isKindOfClass:[UIViewController class]]) {
            //TODO
            break;
        }
    }

你可能感兴趣的:(iOS-返回指定控制器)