创建tabBarControllers视图控制器的方法

时间:2015-01-30 09:11:31   收藏:0   阅读:171
//数组中放各个视图控制器的类名
NSArray *controllersName = [NSArray arrayWithObjects:@"NewsViewController",@"MarketViewController",@"VideoViewController",@"PictureViewController",@"SettingViewController",nil];
NSString *path = [[NSBundle mainBundle] pathForResource:@"Controlles" ofType:@"plist"];
NSArray *channelArrays = [NSArray arrayWithContentsOfFile:path];
NSMutableArray *controllers = [NSMutableArray array];
for (int i = 0; i<controllersName.count; i++) {
//通过类名,得到对应的类
Class class = NSClassFromString([controllersName objectAtIndex:i]);
RootViewController *vc = [[class alloc] initWithChannelArray:[channelArrays objectAtIndex:i]];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:vc];
[controllers addObject:navController];
}
self.viewControllers = controllers;

}


普通的做法都是一个一个创建视图控制器,这样做代码量少了很多。

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!