UIViewController的dismiss跳转多个页面
有多个控制器,依次通过 presentViewController: animated:completion: 方法进行页面跳转,那么如何从最后一个视图控制器跳转会根控制器呢?
假设有四个视图控制器,每个控制器中都有一个UIButton,UIButton的响应方法,依次为
根控制器:
- (void) buttonClicked:(id) sender { A_Controller * controller =[[A_Controller alloc] init]; [self presentViewController: controller animated:YES completion:nil]; }
A控制器:
- (void) buttonClicked:(id) sender { B_Controller * controller =[[B_Controller alloc] init]; [self presentViewController: controller animated:YES completion:nil]; }
B控制器
- (void) buttonClicked:(id)sender { C_Controller * controller = [[C_Controller alloc] init]; [self presentViewController:controller animated:YES completion:nil]; }
C控制器
- (void) buttonClicked:(id) sender { UIViewController * controller = self.presentingViewController; [self dismissViewControllerAnimated:YES completion:^{ UIViewController * c = controller.presentingViewController; [controller dismissViewControllerAnimated:YES completion:^{ [c dismissViewControllerAnimated:YES completion:nil]; }]; }]; }
这样,点击C控制器button的响应方法的时候,就会跳会到根控制器