UITabBarController与UINavigationController配合使用

在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;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值