美文网首页
导航-删除或返回特定VC-(发布详情)

导航-删除或返回特定VC-(发布详情)

作者: 守护地中海的花 | 来源:发表于2019-05-21 17:29 被阅读0次

    导航是堆栈模式 导航控制器类似数组 最新的push的控制器在数组的最后一个元素 pop的控制器 移除数组最后一个元素
    topViewController:就是当前导航控制器管理当前控制器最上层

    • 发布详情界面 一般要删除之前的界面
    - (void)deleteOtherControllers
    {
        //HomeVC  LocalTribeMainVC LocalTribeCircleVC LocalTribePushVC LocalTribeDetailVC 直接发布
        //HomeVC  LocalTribeMainVC  LocalTribeCircleDetailVC LocalTribePushVC LocalTribeDetailVC 在圈子详情里面选择发布
        
        [self.navigationController.viewControllers enumerateObjectsUsingBlock:^(__kindof UIViewController * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
            NSLog(@"%@",obj);
        }];
        NSMutableArray<BaseVC *> *viewControllers = [NSMutableArray array];
        [viewControllers addObjectsFromArray:self.navigationController.viewControllers];
        
        //收藏要被删除vc
        NSMutableArray<BaseVC *> *deleteArray = [NSMutableArray array];
        for (NSInteger index = 0; index < viewControllers.count; index ++) {
            if (index == viewControllers.count - 1 || index == 0) {
                continue;
            }
            if ([viewControllers[index] isMemberOfClass:NSClassFromString(@"LocalTribeCircleVC")]) {
                [deleteArray addObject:viewControllers[index]];
            }
        }
        //删除
        for (NSInteger index = 0; index < deleteArray.count; index ++) {
            [viewControllers removeObject:deleteArray[index]];
        }
        //对接之前的导航
        self.navigationController.viewControllers = viewControllers;
    }
    

    返回特定的VC

    - (void)rushTopSucceed
    {
        //ActivityPageVC ActivityPageDetailManagerVC ActivityVoteDetailVC ShopRushTopVC OrderPreOrderVC
        //ActivityPageVC ActivityPageDetailManagerVC ActivityVoteDetailVC ShopRushTopVC CartPageVC OrderPreOrderVC
        NSLog(@"%@",self.navigationController.viewControllers);
        //收藏要被删除vc
        BaseVC *voteDetailVC;
        for (NSInteger index = (self.navigationController.viewControllers.count - 1); index >= 0; index --) {
            NSLog(@"%@",self.navigationController.viewControllers[index]);
            if (index == self.navigationController.viewControllers.count - 1 || index == 0) {
                continue;
            }
            if ([self.navigationController.viewControllers[index] isMemberOfClass:NSClassFromString(@"ActivityVoteDetailVC")]) {
                voteDetailVC = self.navigationController.viewControllers[index];
                //保证回到就近的投票
                break;
            }
        }
        if (voteDetailVC) {
            [self.navigationController popToViewController:voteDetailVC animated:YES];
        }
    }
    

    相关文章

      网友评论

          本文标题:导航-删除或返回特定VC-(发布详情)

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