建个空的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. java设计模式--创建模式--建造者模式

    对于建造者模式,小编个人理解为就是一个组装型的模式. 建造者模式 概述 将一个复杂对象的构建与它的表示分离,使得同样的构建过程可以创建不同的表示. 适用性 1.当创建复杂对象的算法应该独立于该对象的组 ...

  2. lamp apache配置虚拟主机

    You don't have permission to access /index.php on this server

  3. CentoS6.x网络配置

    一.配置文件 在CentoS系统里面,跟网络有关的主要配置文件有    1./etc/host.conf # 配置域名服务客户端的控制文件 2./etc/hosts # 配置主机名映射为IP的功能 3 ...

  4. android 自定义圆形进度条

    一.通过动画实现 定义res/anim/loading.xml如下: [html]  view plain copy print ?   <?xml version="1.0" ...

  5. C#基础:异步调用 【转】

    首先来看一个简单的例子: 小明在烧水,等水烧开以后,将开水灌入热水瓶,然后开始整理家务 小文在烧水,在烧水的过程中整理家务,等水烧开以后,放下手中的家务活,将开水灌入热水瓶,然后继续整理家务 这也是日 ...

  6. jQuery滑动选取数值范围插件

    HTML 首先载入jQuery库文件以及jRange相关的css文件:jquery.range.css和插件:jquery.range.js <script src="jquery.j ...

  7. PropertyGrid--基本功能

    一.引言 PropertyGrid是Visual Studio中新增的控件,顾名思义,其主要是用来显示和设置某一(或多个)对象的属性值的.其具体的实现主要是基于.Net中强大的反射机制.Propert ...

  8. Mps与Mrp区别

    MPS是完成品的计划表,描述一个特定的完成品的生产时间和生产数量.MPS是一个决定完成品生  产排程及可答应量(ATP)的程序.依据MPS,MRP得以计算在该完成品需求之下,所有组件,零件以  至原材 ...

  9. jQuery基础---Ajax基础教程

    jQuery基础---Ajax基础 内容提纲: 1.Ajax 概述 2.load()方法 3.$.get()和$.post() 4.$.getScript()和$.getJSON() 5.$.ajax ...

  10. Android学习之Notification

    Notification可以在手机的状态栏发出一则通知,它需要用NotificationManager来管理,实现Notification其实很简单. 1.通过getsystemservice方法获得 ...