UINavigationController和UITabBarController的集成
来源:互联网 发布:java简单小程序代码 编辑:程序博客网 时间:2024/04/28 15:07
UINavigationController(导航控制器)和UITabBarController(分栏控制器)的集成有以下两种形式:
第一种:在TabBar控制器中某一个Tab中使用Navigation控制器,这是最常见的一种形式,下面会详细解说;
第二种:在一个Navigation控制器控制下的某一个或某一些控制器是TabBar控制器,这是在对该TabBar控制器进行压入和弹出时与对普通视图控制器的操作方法是一样的。这种方法是不推荐使用的,据说是会出问题的。它的官方文档里有这样一段话:
Because the UITabBarController
class inherits from the UIViewController
class, tab bar controllers have their own view that is accessible through the view
property. When deploying a tab bar interface, you must install this view as the root of your window. Unlike other view controllers, a tab bar interface should never be installed as a child of another view controller.
所以我们在这里只说一下第一种形式的集成。
也就是说将Navigation作为TabBar控制器里某一个TabBarItem所对应的视图控制器。代码如下:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{ self.window = [[UIWindow alloc]initWithFrame:[[UIScreen mainScreen]bounds]]; self.window.backgroundColor = [UIColor whiteColor];
//OneViewController、TwoViewController和ThreeViewController是自己定义的继承自UIViewController的视图控制器类 OneViewController *oneVC = [[OneViewController alloc]init]; UINavigationController *oneNav = [[UINavigationController alloc]initWithRootViewController:oneVC]; TwoViewController *twoVC = [[TwoViewController alloc]init]; ThreeViewController *threeVC = [[ThreeViewController alloc]init]; //注意这里controllerAry里的内容是oneNev,twoVC和threeVC。即第一项是一个UINavigationController类的对象,第二项和第三项是UIViewController类的对象。 NSArray *controllerAry = [[NSArray alloc]initWithObjects:oneNav,twoVC,threeVC, nil]; [oneNav release]; [oneVC release]; [twoVC release]; [threeVC release];
//tabBarConller是定义在AppDelegate.h里的UITabBarController类型的实例变量。 //@property(nonatomic,retain) UITabBarController *tabBarconller; tabBarConller = [[UITabBarController alloc]init]; [tabBarConller.tabBar setBackgroundImage:[UIImage imageNamed:@"beijing.png"]]; tabBarConller.viewControllers = controllerAry; tabBarConller.selectedIndex = 0; //设置每一项tabBarItem的属性(title和image) [(UITabBarItem *)[tabBarConller.tabBar.items objectAtIndex:0] setTitle:@"第一页"]; [(UITabBarItem *)[tabBarConller.tabBar.items objectAtIndex:0]setImage:[UIImage imageNamed:@"one.png"]]; [(UITabBarItem *)[tabBarConller.tabBar.items objectAtIndex:1] setTitle:@"第二页"]; [(UITabBarItem *)[tabBarConller.tabBar.items objectAtIndex:1]setImage:[UIImage imageNamed:@"two.png"]]; [(UITabBarItem *)[tabBarConller.tabBar.items objectAtIndex:2] setTitle:@"第三页"]; [(UITabBarItem *)[tabBarConller.tabBar.items objectAtIndex:2]setImage:[UIImage imageNamed:@"three.png"]]; [self.window addSubview:tabBarConller.view]; //将tabBarController设置为window的根视图 self.window.rootViewController = self.tabBarConller; [self.window makeKeyAndVisible]; [controllerAry release]; return YES;}
以上的代码就创建好了一个以UINavigationController类的实例作为tabBatController里tabBar上的第一个tabBarItem所对应的视图控制器的实例。而OneViewController的实例oneVC是作为oneNav的rootViewController的。
- UINavigationController和UITabBarController的集成
- UITabBarController 和 UINavigationController 的 popToRootViewController
- iOS项目开发实战(Swift)—初探UITabbarController和UINavigationController的集成
- iphone--UIViewController/UITabBarController和UINavigationController的结合
- UINavigationController和UITabBarController共存的例子
- UINavigationController和UITabBarController共存的例子
- UITabBarController 、UIViewController和UINavigationController的简单讲解
- UINavigationController和UITabBarController的组合使用
- UITabBarController和UINavigationController的整合使用
- UINavigationController和UITabBarController合用。
- UINavigationController和UITabBarController合用
- UINavigationController和UITabBarController合用。
- 隐藏UINavigationController和UITabBarController
- UITabBarController和UINavigationController混用
- UINavigationController和UITabBarController合用。
- UINavigationController和UITabBarController
- UINavigationController和UITabBarController混用
- UItabBarController和UINavigationController结合使用
- Spring入门示例及相关概念介绍
- C语言字符串常用操作(持续更新...)
- CakePHP概述
- HTTP POST GET 本质区别详解
- UCenter在JAVA项目中实现的单点登录应用实例
- UINavigationController和UITabBarController的集成
- 彻底删除的硬盘数据怎么恢复
- Java Socket实战之二 多线程通信
- 四月份目标完成情况
- virtualbox 运行时左上角的菜单栏没有了
- JDBC与ODBC的区别与应用
- 如何使用Response.Redirect进行父页面的重定位?
- vlc的Mozilla Plugin
- 表池和表簇