首页 > 代码库 > 创建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;
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视图控制器的方法
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。