iOS UINavigationController 多控制器跳转

例如 UIViewController 是你要跳转的控制器
场景一:根控制器是A,需求是A-->B,B-->C,C-->D,D-->B;
场景二:根控制器是B,需求是B-->C,C-->D,D-->B;

 NSArray* viewArr = self.navigationController.viewControllers;
    if([viewArr[0] isKindOfClass: [UIViewController class]]){
        
        [self.navigationController popToRootViewControllerAnimated:YES];
    }else{
        NSMutableArray *pageArray = [self.navigationController.viewControllers mutableCopy];
        UIViewController *insert = [[UIViewController alloc] init];
        //插入界面栈
        [pageArray insertObject:insert atIndex: 1];
        [self.navigationController setViewControllers:pageArray animated:NO];

        [self.navigationController popToViewController:insert animated:YES];

}

你可能感兴趣的:(iOS UINavigationController 多控制器跳转)