美文网首页iOS接下来要研究的知识点
iOS 多标签切换 代码解耦

iOS 多标签切换 代码解耦

作者: SoaringHeart | 来源:发表于2017-11-07 16:35 被阅读227次

    多标签切换界面解耦,分散代码,避免一个类中代码成千上万行

    思路简单,效果很好

    思路:当前控制器添加其他控制器为子控制器,根据标签切换显示子控制器的View,关键是新建一个UIView做容器

      OneViewController *viewController1 = [[OneViewController alloc] init];
    [self addChildViewController:viewController1];
    
    TwoViewController *viewController2 = [[TwoViewController alloc] init];
    [self addChildViewController:viewController2];
    
    ThreeViewController *viewController3 = [[ThreeViewController alloc] init];
    [self addChildViewController:viewController3];
    
    FourViewController *viewController4 = [[FourViewController alloc] init];
    [self addChildViewController:viewController4];
    
    FiveViewController *viewController5 = [[FiveViewController alloc] init];
    [self addChildViewController:viewController5];
    
    
    - (void)goChangeViewWithIndex:(NSInteger)index{
    
    UIView * view = [[self.childViewControllers firstObject]view];
    if ([self.typeCar isEqualToString:@"0"]) {
        view = [self.childViewControllers[index] view];
        
    }else{
        switch (index) {
            case 0:
            {
                view = [self.childViewControllers[3] view];
    
            }
                break;
            case 1:
            {
                view = [self.childViewControllers[4] view];
    
            }
                break;
            default:
                break;
        }
    }
      [self.containView addSubview:view];
      [self.containView bringSubviewToFront:view];
    }
    
    image

    [图片上传中...(image-56e933-1510043511141-3)]

    image image image

    ChildViewController

    相关文章

      网友评论

        本文标题:iOS 多标签切换 代码解耦

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