博客> About 父子控制器
About 父子控制器
2017-08-17 04:36 评论:0 阅读:252 vistatinchao
ios tabbar controller 父子控制器

import "ViewController.h"

import "OneViewController.h"

import "TwoViewController.h"

import "ThreeViewController.h"

@interface ViewController ()

/ 记录当前的viewController / @property (nonatomic,strong)UIViewController currentVC; @property (nonatomic,strong)NSArray controlers; @end

@implementation ViewController

  • (void)viewDidLoad { [super viewDidLoad]; self.controlers = @[[[OneViewController alloc]init], [[TwoViewController alloc]init], [[ThreeViewController alloc]init]];

}

  • (IBAction)Click:(UIButton *)sender { [self.currentVC.view removeFromSuperview]; NSInteger index = [sender.superview.subviews indexOfObject:sender]; self.currentVC = self.controlers[index]; self.currentVC.view.frame = CGRectMake(0, 70, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height-70); [self.view addSubview:self.currentVC.view];

}

收藏
0
sina weixin mail 回到顶部