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

2019-05-21  本文已影响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];
    }
}
上一篇下一篇

猜你喜欢

热点阅读