iOS POP返回总结

2016-05-12  本文已影响749人  奋撸小菜鸟

1、直接返回到上一层controller

- (nullable UIViewController *)popViewControllerAnimated:(BOOL)animated; // Returns the popped controller.
[self.navigationController popViewControllerAnimated:YES;]

2、直接返回到Root controller

- (nullable NSArray<__kindof UIViewController *> *)popToRootViewControllerAnimated:(BOOL)animated; // Pops until there's only a single view controller left on the stack. Returns the popped controllers.
[self.navigationController popToRootViewControllerAnimated:YES];

3、直接返回到指定的controller

- (nullable NSArray<__kindof UIViewController *> *)popToViewController:(UIViewController *)viewController animated:(BOOL)animated; // Pops view controllers until the one specified is on top. Returns the popped controllers.

方法一:

UIViewController *popCtl;
for (UIViewController *ctl in self.navigationController.viewControllers) {
    if ([ctl isKindOfClass:[MyViewController class]]) {
        popCtl = ctl;
        break;
    }
}
if (popCtl) {
    [self.navigationController popToViewController:popCtl animated:YES];
}

方法二:

NSArray * ctrlArray = self.navigationController.viewControllers;
[self.navigationController popToViewController:[ctrlArray objectAtIndex:1] animated:YES];
上一篇下一篇

猜你喜欢

热点阅读