IOS学习(十七)多视图管理
2016-12-15 00:05
127 查看
#import "MainViewController.h" #import "CustomTabBar.h" #import "OCViewController.h" #import "JAVAViewController.h" #import "PHPViewController.h" @interface MainViewController ()<CustomTabBarDelegate> @property(nonatomic, strong) NSArray *titles; @property(nonatomic, strong) NSMutableArray *arrayViews; @property(nonatomic, strong) NSMutableArray *arrayViewControllers; @property(nonatomic, strong) CustomTabBar *tabBar; @end @implementation MainViewController - (void)viewDidLoad { [super viewDidLoad]; self.view.backgroundColor = [UIColor whiteColor]; self.titles = @[@"OCView", @"JAVAView", @"PHPView"]; // [self addViews:self.titles]; [self addViewControllers]; self.tabBar = [CustomTabBar tabBarWithTites:self.titles]; [self.tabBar setDelegate:self]; [self.view addSubview:self.tabBar]; // [self tabBar:tabBar itemSelectedAtIndex:0]; // [self.tabBar itemButtonSelected:0]; } - (NSMutableArray *)arrayViewControllers{ if (!_arrayViewControllers){ _arrayViewControllers = [NSMutableArray array]; } return _arrayViewControllers; } - (NSMutableArray *)arrayViews{ if (!_arrayViews){ _arrayViews = [NSMutableArray array]; } return _arrayViews; } - (void)addViewControllers{ OCViewController *oc = [[OCViewController alloc] init]; [self.arrayViewControllers addObject:oc]; [self.view addSubview:oc.view]; //必须 [self addChildViewController:oc]; JAVAViewController *java = [[JAVAViewController alloc] init]; [self.arrayViewControllers addObject:java]; [self.view addSubview:java.view]; [self addChildViewController:java]; PHPViewController *php = [[PHPViewController alloc] init]; [self.arrayViewControllers addObject:php]; [self.view addSubview:php.view]; [self addChildViewController:php]; } - (void)addViews:(NSArray *)titles{ for (NSString *className in titles) { UIView *view = [[NSClassFromString(className) alloc] init]; [self.view addSubview:view]; [self.arrayViews addObject:view]; } } - (void)tabBar:(CustomTabBar *)tabBar itemSelectedAtIndex:(NSInteger)index{ // UIView *view = self.arrayViews[index]; // // [self.view bringSubviewToFront:view]; // [self.view bringSubviewToFront:tabBar]; UIViewController *controller = self.arrayViewControllers[index]; [self.view bringSubviewToFront:controller.view]; [self.view bringSubviewToFront:tabBar]; }
//内存紧张时 - (void)didReceiveMemoryWarning{ [super didReceiveMemoryWarning]; NSArray *tmep = [self.arrayViewControllers copy]; for (NSInteger i = 0; i < tmep.count ; i ++){ if (i == self.currentIndex){ continue; } UIViewController * ct = tmep[i]; [ct removeFromParentViewController]; [ct.view removeFromSuperview]; [self.arrayViewControllers removeObject:ct]; ct = nil; } }
相关文章推荐
- iOS富文本编辑器之更"优雅的"实现方法
- [实践]Sonar Xcode8兼容
- ecmobile-ios笔记
- IOS VLC 播放器 开发 滑动快进和后退
- 关于IOS应用签名不一致的问题解决方法
- nagios监控配置详解
- iOS 时间校准解决方案
- iOS 按钮文字图片任意布局,随意定制
- 抽屉菜单
- iOS程序中的内存分配分区
- iOS - 解决was mutated while being enumerated
- iOS 程序引入framework 类别报错unrecognized selector sent to class
- axios基本用法
- 【iOS开发】SEL和Selector 原理小结
- 有关ios中images.xcassets的导入图片等命名问题
- iOS 界面处理放在主线程中
- ios编译linphone 开启x264编译
- [绍棠] iOS获取存储空间大小(总共/剩余)
- iOS - 设置项目工程的图标/启动页