首页 > 代码库 > 创建tabBarControllers视图控制器的方法

创建tabBarControllers视图控制器的方法

//数组中放各个视图控制器的类名
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;

}


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

创建tabBarControllers视图控制器的方法