//
// LYKMainViewController.m
// MeiPaiPai2.0
//
// Created by meipaipai on 17/3/7.
// Copyright © 2017年 meipaipai. All rights reserved.
//
#import "LYKMainViewController.h"
@interface LYKMainViewController ()
@end
@implementation LYKMainViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.tabBar.tintColor = MainColor;
// 设置子视图
[self setupChlidControllers];
}
#pragma mark - 设置子视图
/**
设置子视图
*/
-(void)setupChlidControllers {
// 创建视图控制器数据字典
NSArray *Array = @[
@{@"clsName":@"LYKHomeViewController", @"title":@"首页", @"imageName":@"Ihome"},
@{@"clsName":@"LYKProductViewController", @"title":@"服务", @"imageName":@"Ipro"},
@{@"clsName":@"LYKMakerViewController", @"title":@"供应商", @"imageName":@"Isucai"},
@{@"clsName":@"LYKNewsViewController", @"title":@"资讯", @"imageName":@"Izixun"},
@{@"clsName":@"LYKMineViewController", @"title":@"我的", @"imageName":@"Imine"}
];
// 遍历字典创建视图控制器
NSMutableArray *VcArray = [[NSMutableArray alloc] initWithCapacity:0];
for (NSDictionary *dic in Array) {
[VcArray addObject:[self creatController:dic]];
}
self.viewControllers = VcArray;
}
/**
创建视图控制器
@param dic 视图控制器字典
@return 返回制图控制器
*/
-(UIViewController *)creatController:(NSDictionary *)dic {
// 判断字典中数据知否为空
if (![[dic valueForKey:@"clsName"] isBlankString] && ![[dic valueForKey:@"title"] isBlankString] && ![[dic valueForKey:@"imageName"] isBlankString]) {
NSString *clsName = [dic valueForKey:@"clsName"];
NSString *title = [dic valueForKey:@"title"];
NSString *imageName = [dic valueForKey:@"imageName"];
id vcClass = (UIViewController *)NSClassFromString(clsName);
// 创建视图控制器
UIViewController *vc = [[vcClass alloc] init];
vc.title = title;
vc.tabBarItem.image = [UIImage imageNamed:imageName];
LYKNavigationController *nav = [[LYKNavigationController alloc] initWithRootViewController:vc];
return nav;
}
return [[UIViewController alloc] init];
}
@end
NSClassFromString 创建视图控制器
最新推荐文章于 2019-07-10 18:07:00 发布