美文网首页
iOS POP返回总结

iOS POP返回总结

作者: 奋撸小菜鸟 | 来源:发表于2016-05-12 11:37 被阅读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];
    

    相关文章

      网友评论

          本文标题:iOS POP返回总结

          本文链接:https://www.haomeiwen.com/subject/dnxprttx.html