组合View Controller时遇到的一点问题
View Controller的组合应用其实很常见了,比如说Tab bar controller和Navigation view controller的组合使用,像这种一般都是Navigation view controller作为Tab bar controller的一个child view controller,对应了一个Tab bar item.
然后今天在Review 另外一组的一个产品的代码时,发现他们将Tab bar controller作为了一个普通view controller的child view controller在用,这个用法还是比较奇怪的说,通常基于Tab bar的应用程序都会选择将Tab bar controller作为一个根VC, 而这里面用了一个普通的View Controller作为根VC, 将Tab bar controller作为子VC, 类似下面这样:
[self addChildViewController:mTabBarController];
[self.view addSubview:mTabBarController.view];
据说是为了解决某个奇葩的问题才改成这样的。我只觉得这种方法有不妥之处,但具体哪里不对还真不知道,于是搜了一下官方的文档,看到下面这段:
When combining view controllers, however, the order of containment is important; only certain arrangements are valid. The order of containment, from child to parent, is as follows: Content view controllers, and container view controllers that have flexible bounds (such as the page view controller) Navigation view controller Tab bar controller Split view controller Modal view controllers represent an interruption, they follow slightly different rules. You can present almost any view controller modally at any time. It is far less confusing to present a tab bar controller or navigation controller modally from a custom view controller.
也就是说,这种做法是不合理的,在组合的时候,parent-child之间是有约定的顺序的,Navigation view controller可以作为Tab bar controller的child view controller, 但反过来是不可以的。而Present就没有这个限制了。
当然,假如这么做了会带来什么后果,我暂时还没搞清楚。一般来说,多半是没有维护正确的层级,会导致一些特定的方法不能正确的传递到child view controller而引发一些问题。不过按照官方文档来,还是应该尽量避免这种用法的。
The End.
组合View Controller时遇到的一点问题的更多相关文章
- 自己定义View Controller转换动画
原文链接 : Introduction to Custom View Controller Transitions and Animations 原文作者 : joyce echessa 译文出自 : ...
- presenting view controller
Present ViewController详解 Present ViewController Modally 一.主要用途 弹出模态ViewController是IOS变成中很有用的一个技术,UIK ...
- View Controller Programming Guid for iOS 笔记
1.View Controller 基础 1.1 View Controller 分类 ViewController分为container view controller 和content view ...
- 【IOS笔记】View Controller Basics
View Controller Basics 视图控制器基础 Apps running on iOS–based devices have a limited amount of screen s ...
- iOS Container View Controller
一.UIViewController 做iOS开发的经常会和UIViewController打交道,从类名可知UIViewController属于MVC模型中的C(Controller),说的更具体点 ...
- MVC(Model View Controller)框架
MVC框架 同义词 MVC一般指MVC框架 MVC全名是Model View Controller,是模型(model)-视图(view)-控制器(controller)的缩写,一种软件设计典范,用一 ...
- View Controller Programming Guide for iOS---(七)---Resizing the View Controller’s Views
Resizing the View Controller’s Views A view controller owns its own view and manages the view’s cont ...
- View Controller Programming Guide for iOS---(二)---View Controller Basics
View Controller Basics Apps running on iOS–based devices have a limited amount of screen space for d ...
- View Controller Programming Guide for iOS---(一)---About View Controllers
About View Controllers View controllers are a vital link between an app’s data and its visual appear ...
随机推荐
- jquery事件学习笔记(转载)
一.页面载入1.ready(fn)当DOM载入就绪可以查询及操纵时绑定一个要执行的函数.这是事件模块中最重要的一个函数,因为它可以极大地提高web应用程序的响应速度. 简单地说,这个方法纯粹是对向wi ...
- RequireJS进阶(二) 转
这一篇来认识下打包工具的paths参数,在入门一中就介绍了require.config方法的paths参数.用来配置jquery模块的文件名(jQuery作为AMD模块时id为“jquery”,但文件 ...
- dos 实用命令收集
隐藏文件夹: H:\>attrib gho +h +s +r 解决win2012服务器上网慢:netsh int tcp set global ecn=disable
- springmvc 入门级教程
1.先看下目录结构 2.引用所需的jar文件 3.web.xml 配置如下 <?xml version="1.0" encoding="UTF-8"?&g ...
- Oracle数据库中有关记录个数的查询
一.查询表中全部的记录个数 可用两种方法,一种是在oracle的系统表中统计,另一种需要写存储过程统计,方法分别如下. 1.系统表中统计: SELECT sum(num_rows) FROM user ...
- ANT 发布项目中 build.xml 文件的详细配置
xml 代码 <?xml version="1.0" encoding="UTF-8"?> <!-- name:对应工程名字 default: ...
- python+selenium环境搭建
这里主要基于windows平台. 下载python.http://python.org/getit/ 下载setuptools [python的基础包工具].http://pypi.python.or ...
- selenium python (十)浏览器多窗口处理
#!/usr/bin/python# -*- coding: utf-8 -*-__author__ = 'zuoanvip'#在测试过程中有时候会遇到出现多个浏览器窗口的情况,这时候我们可以通过窗口 ...
- a different object with the same identifier value was already associated with **(ssh异常转)
Hibernate:a different object with the same identifier value was already associated with ...异常解决 今天 ...
- Raspberry Pi3 ~ 配置网络
Rpi3 有两个网卡 一个无线wlan 一个有线 eth0 无线的只需要在右上角的那个配置里面添加就行 有线的需要设置下静态IP.dns.等 在raspbain图形化界面里面 设置 Network P ...