博客>
About 父子控制器
About 父子控制器
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];
}
收藏