Conditionally skipping a UIViewController in an iOS 5 app with UINavigatonController

℡╲_俬逩灬. 提交于 2019-12-05 01:30:15

I use the following code in an app. Works exactly as expected.

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    SecondViewController *secondVC = [self.storyboard instantiateViewControllerWithIdentifier:@"DetailViewController"];
    if (indexPath.row == 0) {
        // skip second vc
        ThirdViewController *thirdVC = [self.storyboard instantiateViewControllerWithIdentifier:@"ThirdViewControllerViewController"];
        [self.navigationController pushViewController:secondVC animated:NO];
        [self.navigationController pushViewController:thirdVC animated:YES];
    }
    else {
        // push second vc
        [self.navigationController pushViewController:secondVC animated:YES];
    }
}

If you want to skip a view controller you can just call UINavigationController setViewControllers:animated: It will animate to the last controller in the supplied array, and the user will be able to "back" out of that stack.

You can build up the array of view controllers any way you like; perhaps starting with the existing array of view controllers:

NSMutableArray* newViewControllers = [[navController.viewcontrollers mutablecopy] autorelease];

[newViewControllers addObject: ...];

[navController setViewControllers: newViewControllers animated: YES];
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!