UITabBarController与UINavigationController异同点浅谈
2015-12-08 19:39
381 查看
UITabBarController与UINavigationController都可以管理多个视图控制器,并且完成视图控制器的切换,并且UITabBarController中可以嵌套UINavigationController,UINavigationController中也可以嵌套UITabBarController
UITabBarController管理多个视图控制器(被管理的视图控制器是平级关系),通过TabBar上的标签切换显示被管理的controller的页面,而UINavigationController则是有上一个页面推出下一个页面
以微信作为例子,在UITabBarController中可以嵌套UINavigationController
//创建被tabVC管理的视图控制器
//微信
VchatViewController *vVC = [[VchatViewController alloc] init];
UINavigationController *nav1 = [[UINavigationController alloc] initWithRootViewController:vVC];
vVC.navigationItem.title = @"微信";
//标签标题
vVC.tabBarItem.title = @"微信";
//设置图片
vVC.tabBarItem.image = [UIImage imageNamed:@"08-chat.png"];
//标签栏标记
vVC.tabBarItem.badgeValue = @"5";
//通讯录
AddressBookViewController *addVC = [[AddressBookViewController alloc] init];
UINavigationController *nav2 = [[UINavigationController alloc] initWithRootViewController:addVC];
addVC.navigationItem.title = @"通讯录";
addVC.tabBarItem.title = @"通讯录";
addVC.tabBarItem.image = [UIImage imageNamed:@"24-gift.png"];
//发现
DiscoverViewController *disVC = [[DiscoverViewController alloc] init];
UINavigationController *nav3 = [[UINavigationController alloc] initWithRootViewController:disVC];
disVC.navigationItem.title = @"发现";
disVC.tabBarItem.title = @"发现";
disVC.tabBarItem.image = [UIImage imageNamed:@"06-magnifying-glass.png"];
disVC.tabBarItem.badgeValue = @"8";
//我
MeViewController *meVC = [[MeViewController alloc] init];
UINavigationController *nav4 = [[UINavigationController alloc] initWithRootViewController:meVC];
meVC.navigationItem.title = @"我";
meVC.tabBarItem.title = @"我";
meVC.tabBarItem.image = [UIImage imageNamed:@"29-heart.png"];
//设置
SettingViewController *setVC = [[SettingViewController alloc] init];
UINavigationController *nav5 = [[UINavigationController alloc] initWithRootViewController:setVC];
setVC.navigationItem.title = @"设置";
setVC.tabBarItem.title = @"设置";
setVC.tabBarItem.image = [UIImage imageNamed:@"19-gear.png"];
// //登陆
// LoginViewController *logVC = [[LoginViewController alloc] init];
// logVC.tabBarItem.title = @"登陆";
// logVC.tabBarItem.image = [UIImage imageNamed:@"38-airplane.png"];
//设置TabBar管理的controller
//当controller超过5个的时候,刺痛会自动增加哦一个”more“标签,管理第五个和五个以上的controller,没有出现在底部的controller会以列表的形式通过点击more展示出来
tabVC.viewControllers = @[nav1, nav2, nav3, nav4, nav5];
//设置tabBarController代理
tabVC.delegate = self;
所显示的页面是
当点击某一个标签时,便会切换到标签对应的页面
UINavigationController的推出视图的方法是:这是由当前页面推出ThreeViewController控制的页面
- (void)goToNextVC:(UIButton *)btn{
ThreeViewController *threeVC = [[ThreeViewController alloc] init];
[self.navigationController pushViewController:threeVC animated:YES];
}
返回上一个页面
- (void)goBackPreviousVC:(UIButton *)btn1{
[self.navigationController popViewControllerAnimated:YES];
}
以上所述只是对两者浅显的对比,我会继续研究的
UITabBarController管理多个视图控制器(被管理的视图控制器是平级关系),通过TabBar上的标签切换显示被管理的controller的页面,而UINavigationController则是有上一个页面推出下一个页面
以微信作为例子,在UITabBarController中可以嵌套UINavigationController
//创建被tabVC管理的视图控制器
//微信
VchatViewController *vVC = [[VchatViewController alloc] init];
UINavigationController *nav1 = [[UINavigationController alloc] initWithRootViewController:vVC];
vVC.navigationItem.title = @"微信";
//标签标题
vVC.tabBarItem.title = @"微信";
//设置图片
vVC.tabBarItem.image = [UIImage imageNamed:@"08-chat.png"];
//标签栏标记
vVC.tabBarItem.badgeValue = @"5";
//通讯录
AddressBookViewController *addVC = [[AddressBookViewController alloc] init];
UINavigationController *nav2 = [[UINavigationController alloc] initWithRootViewController:addVC];
addVC.navigationItem.title = @"通讯录";
addVC.tabBarItem.title = @"通讯录";
addVC.tabBarItem.image = [UIImage imageNamed:@"24-gift.png"];
//发现
DiscoverViewController *disVC = [[DiscoverViewController alloc] init];
UINavigationController *nav3 = [[UINavigationController alloc] initWithRootViewController:disVC];
disVC.navigationItem.title = @"发现";
disVC.tabBarItem.title = @"发现";
disVC.tabBarItem.image = [UIImage imageNamed:@"06-magnifying-glass.png"];
disVC.tabBarItem.badgeValue = @"8";
//我
MeViewController *meVC = [[MeViewController alloc] init];
UINavigationController *nav4 = [[UINavigationController alloc] initWithRootViewController:meVC];
meVC.navigationItem.title = @"我";
meVC.tabBarItem.title = @"我";
meVC.tabBarItem.image = [UIImage imageNamed:@"29-heart.png"];
//设置
SettingViewController *setVC = [[SettingViewController alloc] init];
UINavigationController *nav5 = [[UINavigationController alloc] initWithRootViewController:setVC];
setVC.navigationItem.title = @"设置";
setVC.tabBarItem.title = @"设置";
setVC.tabBarItem.image = [UIImage imageNamed:@"19-gear.png"];
// //登陆
// LoginViewController *logVC = [[LoginViewController alloc] init];
// logVC.tabBarItem.title = @"登陆";
// logVC.tabBarItem.image = [UIImage imageNamed:@"38-airplane.png"];
//设置TabBar管理的controller
//当controller超过5个的时候,刺痛会自动增加哦一个”more“标签,管理第五个和五个以上的controller,没有出现在底部的controller会以列表的形式通过点击more展示出来
tabVC.viewControllers = @[nav1, nav2, nav3, nav4, nav5];
//设置tabBarController代理
tabVC.delegate = self;
所显示的页面是
当点击某一个标签时,便会切换到标签对应的页面
UINavigationController的推出视图的方法是:这是由当前页面推出ThreeViewController控制的页面
- (void)goToNextVC:(UIButton *)btn{
ThreeViewController *threeVC = [[ThreeViewController alloc] init];
[self.navigationController pushViewController:threeVC animated:YES];
}
返回上一个页面
- (void)goBackPreviousVC:(UIButton *)btn1{
[self.navigationController popViewControllerAnimated:YES];
}
以上所述只是对两者浅显的对比,我会继续研究的
相关文章推荐
- UIWindow
- 使用 IBM Bluemix 容器构建 Django 环境
- UITableView中Cell重用机制导致内容重复覆盖
- IOS UITextView 和 UITextField 联想输入法字数限制
- UITextView 如何使显示不全的单词不折行显示
- Initial job has not accepted any resources; check your cluster UI to ensure that workers are registe
- 管理工具MongoVUE使用
- 源码探索系列1---Handler与HandlerLeak的那些事
- Web UI 优化自动化测试用例的稳定性
- The X New Developer’s Guide——第一章 基本概念
- Web UI自动化测试框架 使用递归一次性加载配置文件信息(.properties)
- UItextView,UIscrollView,UITableViewCell三种能够使页面滑动控件的总结(3)
- ReferenceQueue的使用
- Volley源码解析(二):RequestQueue
- ZZULIOJ 1801 xue姐的小动物
- POJ 3080 Blue Jeans
- 学习 easyui 之一:easyloader 分析与使用
- UI第十九天:数据库
- pcduino nfs挂在光盘
- UItextView,UIscrollView,UITableViewCell三种能够使页面滑动控件的总结(1)