建个空的iOS工程

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
//
MyFirstViewController *viewCtrl1 = [[MyFirstViewController alloc] init];
viewCtrl1.title = @"viewctrl1";
viewCtrl1.view.backgroundColor = [UIColor blueColor];
UINavigationController *navgCtrl1 = [[UINavigationController alloc] initWithRootViewController: viewCtrl1];
//
UIViewController *viewCtrl2 = [[UIViewController alloc] init];
viewCtrl2.title = @"viewctrl2";
viewCtrl2.view.backgroundColor = [UIColor redColor];
UINavigationController *navgCtrl2 = [[UINavigationController alloc] initWithRootViewController: viewCtrl2];
//
UIViewController *viewCtrl3 = [[UIViewController alloc] init];
viewCtrl3.title = @"viewctrl3";
viewCtrl3.view.backgroundColor = [UIColor yellowColor];
UINavigationController *navgCtrl3 = [[UINavigationController alloc] initWithRootViewController: viewCtrl3];
//
UITabBarController *tabBarCtrl = [[UITabBarController alloc] init];
tabBarCtrl.view.frame = self.window.frame;
tabBarCtrl.viewControllers = [NSArray arrayWithObjects: navgCtrl1 ,navgCtrl2, navgCtrl3 ,nil]; self.window.rootViewController = tabBarCtrl; return YES;
}

创建自定义 MyFirstViewController (继承自UIViewController)

 
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button addTarget:self action:@selector(Target:) forControlEvents:UIControlEventTouchUpInside];
[button setTitle:@"Target" forState:UIControlStateNormal];
button.frame = CGRectMake(100, 200, 120, 44);
[self.view addSubview:button];
}
-(void)Target:(id)sender
{
ChangeViewController *changViewCtrl = [[ChangeViewController alloc] init]; [self.navigationController pushViewController:changViewCtrl animated:YES];
}
 

自定义ViewController ChangeViewController

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor = [UIColor colorWithRed:0.5 green:0.1 blue:0.9 alpha:1.0];
}

小结: 用UINavigationController 配合 UITabBarController,很多app都用到这样的交互,其关键点在于,给每个视图控制器(ViewController)添加导航控制器(UINavigationController).

UINavigationController *navgCtrl1 = [[UINavigationController alloc] initWithRootViewController: viewCtrl1];

把导航控制器打包进TabBarController

tabBarCtrl.viewControllers = [NSArray arrayWithObjects: navgCtrl1 ,navgCtrl2, navgCtrl3 ,nil];

把tabBarController设为应用程序rootViewController.

self.window.rootViewController = tabBarCtrl;

这样的话,导航控制器的后续操作可以参考自己以前写的关于 UINavigationController 的用法。以及自定义TabBarItem,在前篇文章中也有说明.

UITabBarController 笔记(三) UITabBarController 配合 UINavigationController 的使用的更多相关文章

  1. 响应式编程笔记三:一个简单的HTTP服务器

    # 响应式编程笔记三:一个简单的HTTP服务器 本文我们将继续前面的学习,但将更多的注意力放在用例和编写实际能用的代码上面,而非基本的APIs学习. 我们会看到Reactive是一个有用的抽象 - 对 ...

  2. Oracle学习笔记三 SQL命令

    SQL简介 SQL 支持下列类别的命令: 1.数据定义语言(DDL) 2.数据操纵语言(DML) 3.事务控制语言(TCL) 4.数据控制语言(DCL)  

  3. 《CMake实践》笔记三:构建静态库(.a) 与 动态库(.so) 及 如何使用外部共享库和头文件

    <CMake实践>笔记一:PROJECT/MESSAGE/ADD_EXECUTABLE <CMake实践>笔记二:INSTALL/CMAKE_INSTALL_PREFIX &l ...

  4. Mastering Web Application Development with AngularJS 读书笔记(三)

    第一章笔记 (三) 一.Factories factory 方法是创建对象的另一种方式,与service相比更灵活,因为可以注册可任何任意对象创造功能.例如: myMod.factory('notif ...

  5. Python 学习笔记三

    笔记三:函数 笔记二已取消置顶链接地址:http://www.cnblogs.com/dzzy/p/5289186.html 函数的作用: 給代码段命名,就像变量給数字命名一样 可以接收参数,像arg ...

  6. 《MFC游戏开发》笔记三 游戏贴图与透明特效的实现

    本系列文章由七十一雾央编写,转载请注明出处. 313239 作者:七十一雾央 新浪微博:http://weibo.com/1689160943/profile?rightmod=1&wvr=5 ...

  7. [Firefly引擎][学习笔记三][已完结]所需模块封装

    原地址:http://www.9miao.com/question-15-54671.html 学习笔记一传送门学习笔记二传送门 学习笔记三导读:        笔记三主要就是各个模块的封装了,这里贴 ...

  8. JSP学习笔记(三):简单的Tomcat Web服务器

    注意:每次对Tomcat配置文件进行修改后,必须重启Tomcat 在E盘的DATA文件夹中创建TomcatDemo文件夹,并将Tomcat安装路径下的webapps/ROOT中的WEB-INF文件夹复 ...

  9. 构建高性能WEB站点笔记三

    构建高性能WEB站点笔记三 第10章 分布式缓存 10.1数据库的前端缓存区 文件系统内核缓冲区,位于物理内存的内核地址空间,除了使用O_DIRECT标记打开的文件以外,所有对磁盘文件的读写操作都要经 ...

随机推荐

  1. (八)boost库之异常处理

    (八)boost库之异常处理 当你面对上千万行的项目时,当看到系统输出了异常信息时,你是否想过,如果它能将文件名.行号等信息输出,该多好啊,曾经为此绞尽脑汁. 今天使用boost库,将轻松的解决这个问 ...

  2. [x-means] 1.x-means简介

    本文基于<X-means>和<BIC-notes>(原论文中BIC公式有误,这是对BIC的补充) K-means的缺点 每一轮迭代的计算花费大 需要用户指定K 易于收敛到局部最 ...

  3. Poj 1269 Intersecting Lines_几何模板

    #include <iostream> #include <math.h> #include <iomanip> #define eps 1e-8 #define ...

  4. linux共享内存简析

    共享内存是IPC的一种机制,允许两个不相关的进程共享同一块内存 //共享内存可以双向通信,但其本身没有相应机制,需要程序编写者设计,本例为单向通信(分为读端和写端). 共享内存读端: #include ...

  5. [tarjan] poj 1236 Network of Schools

    主题链接: http://poj.org/problem?id=1236 Network of Schools Time Limit: 1000MS   Memory Limit: 10000K To ...

  6. Android得到一个闹钟在第三方

    收集报警信息 闹铃时间,闹铃备注信息 闹铃引起系统变化的点: 1. Send Notification (正点闹钟能够设置不发送) 2. Play audio 闹铃信息结构体 ClockInfo{ S ...

  7. Open Replicator

    Open Replicator ( http://code.google.com/p/open-replicator/ ) 开源了.Open Replicator是一个用Java编写的MySQL bi ...

  8. 小心ThreadLocal的陷阱

    ThreadLocal用在多线程时保存线程级的局部变量,当我们需要在线程内共享数据时,ThreadLocal屡试不爽,但是ThreadLocal也会有一个问题,当你使用线程池时,线程可能会被重用,所以 ...

  9. T-SQL事务

    事务 订火车票的时候,下一个订单,这个订单中,包含多个购买信息,要么全部执行,要么全部不执行,合作事务就是来处理这种模型的一种机制. --关键字:transaction 或 tran 简写形式 --开 ...

  10. javascript模式——Command

    假设我们要做一个计算器程序 var calculator = { add: function( x, y ){ return x + y; }, sub: function( x, y ){ retu ...