UINavigationController和UITabBarController合用[转载比较好理解]
来源:互联网 发布:qq视频变声软件 编辑:程序博客网 时间:2024/03/29 08:18
原文地址:http://blog.csdn.net/lovefqing/article/details/8255846
很多时候我们创建一个基于UITabBarController的application以后还希望能够在每个tab view都可以实现导航控制,即添加一个UINavigationController来实现tabview内部的view之间的切换,这即是本文所要介绍的。
一、创建一个 Tabbed Application.默认创建的是带有两个Tab的工程。
二、在AppDelegate.h里面添加
- @property (strong, nonatomic) UINavigationController *NaviView1Controller;
- @property (strong, nonatomic) UINavigationController *NaviView2Controller;
三、修改AppDelegate.m文件的didFinishLaunchingWithOptions函数,在这里我们设置相应的UINavigationController.
修改前:
- - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
- {
- self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
- // Override point for customization after application launch.
- UIViewController *viewController1 = [[[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil] autorelease];
- UIViewController *viewController2 = [[[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil] autorelease];
- self.tabBarController = [[[UITabBarController alloc] init] autorelease];
- self.tabBarController.viewControllers = @[viewController1, viewController2];
- self.window.rootViewController = self.tabBarController;
- [self.window makeKeyAndVisible];
- return YES;
- }
- - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
- {
- self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
- // Override point for customization after application launch.
- UIViewController *viewController1 = [[[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil] autorelease];
- viewController1.title = @"View1";
- self.NaviView1Controller = [[[UINavigationController alloc] initWithRootViewController:viewController1] autorelease];
- UIViewController *viewController2 = [[[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil] autorelease];
- viewController2.title = @"View2";
- self.NaviView2Controller = [[[UINavigationController alloc] initWithRootViewController:viewController2] autorelease];
- self.tabBarController = [[[UITabBarController alloc] init] autorelease];
- self.tabBarController.viewControllers = @[self.NaviView1Controller, self.NaviView2Controller];
- self.window.rootViewController = self.tabBarController;
- [self.window makeKeyAndVisible];
- return YES;
- }
运行一下程序,可以看到每个Tab view都自动多了一个NavigationBar在顶部。
三、添加两个新的View测试NavigationController。
1. 创建Test1ViewController类,以及对应的xib文件。
2. 创建Test2ViewController类,以及对应的xib文件。
3. 如果你的iPhone iOS版本低于6.0,在xib的设置里需要勾掉autolayout选项。
四、在Tab view 1的xib文件里添加一个按钮,并设置相应的IBOutlet, IBAction.如下图:
五、编写代码逻辑。
在FirstViewController.m中。编写函数gotoTest1View
- - (IBAction)gotoTest1View:(id)sender {
- Test1ViewController *SRDVController = [[Test1ViewController alloc]init];
- [self.navigationController pushViewController:SRDVController animated:YES];
- [SRDVController release];
- }
六、代码下载:http://download.csdn.net/detail/lovefqing/4845092
若本文和代码有任何错误,欢迎拍砖指正!
0 0
- UINavigationController和UITabBarController合用[转载比较好理解]
- UINavigationController和UITabBarController合用。
- UINavigationController和UITabBarController合用
- UINavigationController和UITabBarController合用。
- UINavigationController和UITabBarController合用。
- 隐藏UINavigationController和UITabBarController
- UITabBarController和UINavigationController混用
- UINavigationController和UITabBarController
- UINavigationController和UITabBarController混用
- UItabBarController和UINavigationController结合使用
- UINavigationController和UITabBarController的集成
- UITabBarController 和 UINavigationController 的 popToRootViewController
- iOS 自定义UINavigationController和UITabBarController
- UINavigationController和UITabbarController内部结构解析
- UITabBarController和UINavigationController搭配使用
- UINavigationController跳转到UITabBarController和UITabBarController跳转到 UINavigationController
- UINavigationController跳转到UITabBarController和UITabBarController跳转到 UINavigationController
- UINavigationController,UITabBarController
- POJ 3660 Cow Contest (Floyd求传递闭包)
- android 倒计时处理
- BZOJ 2530 Poi2011 Party 构造
- sudo apt-get remove vim-common不成功,提示被锁Could not get lock /var/lib/dpkg/lock
- 简单的几行小代码,实现Android程序布局替换。
- UINavigationController和UITabBarController合用[转载比较好理解]
- Sensor信号输出YUV、RGB、RAW DATA、JPEG 4种方式区别
- Unity design patterns and concepts, looking for good sources
- Payment Terms 付款条件
- C++12.2 隐含的this指针(不懂)、mutable数据成员
- 我曾经面试过这样一个问题
- 今日之谬言,不谦谓悟道
- 灰度图转伪彩色图
- 快捷键让SublimeText在编文件快速在浏览器打开