UITabBarController与UINavigationController配合使用
2015-06-16 11:41
537 查看
在ios应用开发中,最常用的一种方式就是UITabBarController与UINavigationController配合使用。
这篇文章主要以一个含两个标签面的应用来介绍一下两种情况:
1.UITabBarController各子界面是独立的导航关系,互不影响,启动代码如下:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
// 整体是一个UITabBarController,每个界面都是一个UINavigationCongtroller。UIViewController *viewController1 = [[[FirstViewController alloc] initWithNibName:@”FirstViewController” bundle:nil] autorelease];
UIViewController *viewController2 = [[[SecondViewController alloc] initWithNibName:@”SecondViewController” bundle:nil] autorelease];
UINavigationController* nav1 = [[[UINavigationController alloc] initWithRootViewController:viewController1] autorelease];
UINavigationController* nav2 = [[[UINavigationController alloc] initWithRootViewController:viewController2] autorelease];
UITabBarController* tabBarController = [[[UITabBarController alloc] init] autorelease];
tabBarController.viewControllers = [NSArray arrayWithObjects:nav1,nav2, nil];
// 这里是不同之处是,根界面UITabBarController
self.window.rootViewController = tabBarController;
[self.window makeKeyAndVisible];
return YES;
}
2.应用整体是一个导航关系,只在根界面上分tab页。启动代码如下:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
// 整体是一个UINavigationController,根界面包含两个tabBar界面。
UIViewController *viewController1 = [[[FirstViewController alloc] initWithNibName:@”FirstViewController” bundle:nil] autorelease];
UIViewController *viewController2 = [[[SecondViewController alloc] initWithNibName:@”SecondViewController” bundle:nil] autorelease];
UITabBarController* tabBarController = [[[UITabBarController alloc] init] autorelease];
tabBarController.viewControllers = [NSArray arrayWithObjects:viewController1,viewController2, nil];
UINavigationController* navController = [[[UINavigationController alloc] initWithRootViewController:tabBarController] autorelease];
// 这里是不同之处是,根界面UINavigationController
self.window.rootViewController = navController;
[self.window makeKeyAndVisible];
return YES;
}
相关文章推荐
- 114自定义UITableViewCell(扩展知识:为UITableViewCell添加动画效果)
- Axure制作手机UI原型之界面滑动滚动效果
- UE4教程&论坛
- 多线程之-NSOperationQueue
- UI之单例模式
- web.xml中dispatcher标签详解
- (转)通过Chisel加强LLDB的UI调试能力
- 如何使用NSOperations和NSOperationQueues
- 【EasyUI学习-3】Easyui tabs入门实践
- Implement Stack using Queues
- 常用设备类别及其GUID
- IOS UIScrollView中 使用 touch 无法响应的问题
- IOS Key-Value Observing (KVO)
- IOS Key-Value Observing (KVO)
- 【Android UI设计与开发】第09期:底部菜单栏(四)Fragment+PopupWindow仿QQ空间最新版底部菜单栏
- 【uiautomator】UiDevice
- Android stuido debug调试
- VS2008工程移植到2010的问题'system.io.fileloadexception was unhandled message=mixed mode assembly is built ag
- 【Android UI设计与开发】第08期:底部菜单栏(三)Fragment+FragmentTabHost实现仿新浪微博底部菜单栏
- LeetCode OJ 之 Implement Stack using Queues(使用队列实现栈)