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时遇到的一点问题的更多相关文章

  1. 自己定义View Controller转换动画

    原文链接 : Introduction to Custom View Controller Transitions and Animations 原文作者 : joyce echessa 译文出自 : ...

  2. presenting view controller

    Present ViewController详解 Present ViewController Modally 一.主要用途 弹出模态ViewController是IOS变成中很有用的一个技术,UIK ...

  3. View Controller Programming Guid for iOS 笔记

    1.View Controller 基础 1.1 View Controller 分类 ViewController分为container view controller 和content view ...

  4. 【IOS笔记】View Controller Basics

    View Controller Basics   视图控制器基础 Apps running on iOS–based devices have a limited amount of screen s ...

  5. iOS Container View Controller

    一.UIViewController 做iOS开发的经常会和UIViewController打交道,从类名可知UIViewController属于MVC模型中的C(Controller),说的更具体点 ...

  6. MVC(Model View Controller)框架

    MVC框架 同义词 MVC一般指MVC框架 MVC全名是Model View Controller,是模型(model)-视图(view)-控制器(controller)的缩写,一种软件设计典范,用一 ...

  7. 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 ...

  8. 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 ...

  9. 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 ...

随机推荐

  1. 【转】gcc中-pthread和-lpthread的区别

    原文网址:http://chaoslawful.iteye.com/blog/568602 用gcc编译使用了POSIX thread的程序时通常需要加额外的选项,以便使用thread-safe的库及 ...

  2. python-socket.error[10054]:对象的复制

    1.socket.error[10054],对方强制关闭了连接 在用socket.recvfrom时,若事先没有bind时, 先使用socket.sendto,socket.recvfrom 有时会出 ...

  3. [Papers]NSE, $u$, Lorentz space [Bjorland-Vasseur, JMFM, 2011]

    $$\bex \int_0^T\frac{\sen{\bbu}_{L^{q,\infty}}^p}{\ve+\ln \sex{e+\sen{\bbu}_{L^\infty}}}\rd s<\in ...

  4. Selenium2Library系列 keywords 之 _ElementKeywords

    #公有方法: (1)current_frame_contains(self, text, loglevel='INFO') (2)current_frame_should_not_contain(se ...

  5. Chapter13:拷贝控制

    拷贝控制操作:拷贝构造函数.拷贝赋值运算符.移动构造函数.移动赋值运算符.析构函数. 实现拷贝控制操作的最困难的地方是首先认识到什么时候需要定义这些操作. 拷贝构造函数: 如果一个构造函数的第一个参数 ...

  6. MVC用户登录方法(lamda表达式)

        public bool ValidateUser(account model) { using (assertEntities db = new assertEntities()) { acc ...

  7. win7的centos虚拟机上搭建mysql5.6服务

    1 安装包下载 mysql5.6下载地址: http://dev.mysql.com/downloads/mysql/ 这里选择linux版本: navicat11破解版的下载地址: http://d ...

  8. ruby 安装更新

    wget http://cache.ruby-lang.org/pub/ruby/2.2/ruby-2.2.2.tar.gz tar xfvz ruby-2.2.2.tar.gz cd ruby-2. ...

  9. CodeForces 622 A.Infinite Sequence

    A.Infinite Sequence time limit per test 1 second memory limit per test 256 megabytes input standard ...

  10. 转自 处理老版PIL 到 pillow

    帮新同事部署开发环境, 由于项目代码里用到了PIL库处理图片, 导致一些图片在浏览器中无法正常显示.  几番折腾, 解决了问题, 这里记录一下报的问题, 及解决方法: 1. python版本不对, 6 ...