搭建NavigationController+TabBar的通用步骤。
这种架构的应用会经常使用,特此记录。
1、新建项目,删除Deployment Info下的Main Interface里的“Main”
2、新建UITabBarController或导入第三方Tabbar。
3、如果是第三方,则根据第三方方法进行设置;若为自己建立的TabbarController,则在TabBar的.m内进行设置。
1)编写添加所有子视图控制器方法:
-(void) viewdidload{
[super viewdidload];
[self setUpAllChildViewController];
}
- (void)setUpAllChildViewController{ // 1.添加第一个控制器
1、新建项目,删除Deployment Info下的Main Interface里的“Main”
2、新建UITabBarController或导入第三方Tabbar。
3、如果是第三方,则根据第三方方法进行设置;若为自己建立的TabbarController,则在TabBar的.m内进行设置。
1)编写添加所有子视图控制器方法:
-(void) viewdidload{
[super viewdidload];
[self setUpAllChildViewController];
}
- (void)setUpAllChildViewController{ // 1.添加第一个控制器
UIViewController *oneVC = [[UIViewController alloc]init];
[self setUpOneChildViewController:oneVC image:[UIImage imageNamed:@"tab_home_icon"] title:@"111"]; // 2.添加第2个控制器
UITableViewController *twoVC = [[UITableViewController alloc]init];
[self setUpOneChildViewController:twoVC image:[UIImage imageNamed:@"js"] title:@"222"]; // 3.添加第3个控制器
UIViewController *threeVC = [[UIViewController alloc]init];
[self setUpOneChildViewController:threeVC image:[UIImage imageNamed:@"qw"] title:@"333"]; // 4.添加第4个控制器
UITableViewController *fourVC = [[UITableViewController alloc]init];
[self setUpOneChildViewController:fourVC image:[UIImage imageNamed:@"user"] title:@"444"];
}
[self setUpOneChildViewController:fourVC image:[UIImage imageNamed:@"user"] title:@"444"];
}
2)/**
* 添加一个子控制器的方法
*/
- (void)setUpOneChildViewController:(UIViewController *)viewController image:(UIImage *)image title:(NSString *)title{ UINavigationController *navC = [[UINavigationController alloc]initWithRootViewController:viewController];
navC.title = title;
navC.tabBarItem.image = image;
[navC.navigationBar setBackgroundImage:[UIImage imageNamed:@"abcde"] forBarMetrics:UIBarMetricsDefault];
viewController.navigationItem.title = title;
[self addChildViewController:navC];
}
ok~
评论
发表评论