UINavigationController .h
+(instancetype)navigationControllerWithController:(UIViewController *)vc Title:(NSString *)title Image:(NSString *)imageName SelectedImage:(NSString *)SelectedImageName;
UINavigationController.m
+ (instancetype)navigationControllerWithController:(UIViewController *)vc Title:(NSString *)title Image:(NSString *)imageName SelectedImage:(NSString *)SelectedImageName{
NavViewController *nav = [[NavViewController alloc]initWithRootViewController:vc];
[nav.tabBarItem setTitle:title];
[nav.tabBarItem setImage:[[UIImage imageNamed:imageName]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
[nav.tabBarItem setSelectedImage:[[UIImage imageNamed:SelectedImageName]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
return nav;
}
TabbarViewController.m
- (void)viewDidLoad {
[super viewDidLoad];
aViewController *a = [[aViewController alloc]init];
NavViewController *nava = [NavViewController navigationControllerWithController:a Title:@"首页" Image:@"1" SelectedImage:@"1_"];
bViewController *b = [[bViewController alloc]init];
NavViewController *navb = [NavViewController navigationControllerWithController:b Title:@"微淘" Image:@"2" SelectedImage:@"2_"];
cViewController *c = [[cViewController alloc]init];
NavViewController *navc = [NavViewController navigationControllerWithController:c Title:@"购物车" Image:@"3" SelectedImage:@"3_"];
dViewController *d = [[dViewController alloc]init];
NavViewController *navd = [NavViewController navigationControllerWithController:d Title:@"公益" Image:@"4" SelectedImage:@"4_"];
eViewController *e = [[eViewController alloc]init];
NavViewController *nave = [NavViewController navigationControllerWithController:e Title:@"我的" Image:@"5" SelectedImage:@"5_"];
self.viewControllers = @[nava,navb,navc,navd,nave];
}
封装传值Tabbar