UITabBarController 和 UINavigationController 的详解
首先得搞清这两个控制器之间的层级关系,我们直接看官网给的图,如下所示:
从这张图可以看到:最右边的Assembled views是呈现给用户的界面,它左边的Window是最底层的窗口,重点来了,再往左,是Tab bar view,Tab bar view的上方是Navigation view,最后是用户定制的视图。
看完这个,代码就应该很好写了,我们需要把Navigation view加到 Tab bar view的内容上去,Tab bar view再加到Window上去。就是Window套UITabBarController,UITabBarController套UINavigationController, UINavigationController套UIViewController。
UIViewControlleller 的tabBarItem的详情里面最后一句话:
The default value is a tab bar item that displays the view controller'€™s title.
标签栏元素默认显示的是 视图控制器的标题。
navigationItem 里面同样有这么一句话
The default behavior is to create a navigation item that displays the view controller'€™s title.
默认创建一个导航栏元素显示 视图控制器的标题
1.因此 activetyLC.title = @"活动"; 同时给导航栏和标签栏赋值 就有迹可循了。
2. 若 我们的导航栏标题 和标签栏 标题显示的不一样的时候如何赋值呢。
UIViewController是UINavigationController和 UITabBarController的父类
我们看下UIViewController里面的navigationItem 和 tabBarItem 是如何说明的
The tab bar item that represents the view controller when added to a tab bar controller.
标签栏元素 代表 控制器被 添加到的标签栏控制器 的标签栏元素 (父标签栏 标签元素)
The navigation item used to represent the view controller in a parent'€™s navigation bar. (read-only)
导航栏元素代表着 父视图控制器的导航栏 元素 (父 导航栏 导航元素)
按照上面我所说的层次关系,在 最上层的 UIViewController
这样写:
self.navigationItem.title = @"活动";
self.tabBarItem.title = @"活动123"; 会如何??
结果是: 导航栏 标题 显示 “活动” ,标签栏为 “空”。
若我们给导航栏的 tabBarItem 赋值。
activetyNC.tabBarItem.title = @"活动";
则 标签栏 正常显示 “活动”。
结合上面的 UIViewController里面对 导航元素和 标签元素的 介绍。 这样就明白了。
虽然
UINavigationController和 UITabBarController 都继承自 UIViewController,他们中都有 标签元素和导航元素属性,但是
对于:UIViewController navigationItem 和 tabBarItem 没有赋值,则为空,若父视图为导航栏控制器,navigationItem为 导航栏控制器的 navigationItem; 若父类为 标签控制器,则 tabBarItem为 标签控制器的 tabBarItem。
UITabBarController 和 UINavigationController 的详解的更多相关文章
- UINavigationController使用详解
UINavigationController使用详解 有一阵子没有写随笔,感觉有点儿手生.一个多月以后终于又一次坐下来静下心写随笔,记录自己的学习笔记,也希望能够帮到大家. 废话少说回到正题,UINa ...
- UI第六节——UINavigationController 详解
1. UINavigationController 是一个容器类.里面盛放的是UIViewController. 容器的意思是,如果你不放入UIViewController,里面就是空的,什么也没有. ...
- UINavigationController 、UINavigationBar 、UINavigationItem 超清晰直观详解
UINavigationController 部分 1. UINavigationController 是一个容器类.里面盛放的是UIViewController. 容器的意思是,如果你不放入UIVi ...
- iOS开发——控制器OC篇&UINavigationController&UITabBarController详解
UINavigationController&UITabBarController详解 一:UINavigationController 控制器的属性: UINavigationControl ...
- iOS学习之UINavigationController详解与使用(一)添加UIBarButtonItem
http://blog.csdn.net/totogo2010/article/details/7681879 1.UINavigationController导航控制器如何使用 UINavigati ...
- [转]iOS学习之UINavigationController详解与使用(三)ToolBar
转载地址:http://blog.csdn.net/totogo2010/article/details/7682641 iOS学习之UINavigationController详解与使用(二)页面切 ...
- UINavigationController详解一(转)UIBarButtonItem
本文出自:http://www.cnblogs.com/smileEvday/archive/2012/05/14/2495153.html 特别感谢. 1.UINavigationControlle ...
- [转]iOS学习之UINavigationController详解与使用(二)页面切换和segmentedController
转载地址:http://blog.csdn.net/totogo2010/article/details/7682433 iOS学习之UINavigationController详解与使用(一)添加U ...
- UITabBarController详解
UITabBarController使用详解 UITabBarController是IOS中很常用的一个viewController,例如系统的闹钟程序,ipod程序等.UITabBarControl ...
随机推荐
- sense之间的数据传输
下面介绍一种原界面向目标界面传值 和 两种 由目标界面返回值给原界面的方法 界面解释: a界面和b界面都在导航控制器中, a界面触发时间跳转至b界面,b界面上设定完毕数据后返回a界面 a界面:原界面 ...
- spring restTemplate 用法
发出get请求,方式一 String url = serverUrl+"/path/path?id={id}"; int i = restTemplate.getForObject ...
- FineReport——JS监听其他控件事件
首先在参数面板和报表中分布添加一个button,用于被监听: 参数面板 控件名:temp: temp点击事件:alert("temp"); 报表 控件名:exprt: temp点击 ...
- [ python ] 类中的一些特殊方法
item系列 __getitem__(self, item) 对象通过 object[key] 触发 __setitem__(self, key, value) 对象通过 object[key] = ...
- mysql性能分析-------profiling和explain
1. profiling之性能分析 MySQL5.0.37版本以上支持了Profiling – 官方手册.此工具可用来查询 SQL 会执行多少时间,System lock和Table lock 花多少 ...
- HDU-4255
A Famous Grid Time Limit: 10000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- python类的使用与多文件组织
多文件的组织 跨目录级导入模块 from ..xxfile import xxmodule #从上级目录中的xxfile中导入xxmodule import xxsub_dir.xxfile #从xx ...
- CentOS7.5字体美化
背景知识 有衬线 (Serif) 无衬线 (Sans Serif) 和等宽 (Monospace) 字型 1 有衬线 (Serif) 字型是比较正式的字体,比划粗细不一,在笔划的边缘有装饰部分(我的理 ...
- nginx安装及配置文件详解
一)nginx安装及模块讲解 1.1.nginx安装步骤 mkdir /soft wget http://nginx.org/download/nginx-1.12.0.tar.gz tar zxf ...
- Codeforces 1082 A. Vasya and Book-题意 (Educational Codeforces Round 55 (Rated for Div. 2))
A. Vasya and Book time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...