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. trunc的使用

    1.日期比较时精确到日,可以使用 TRUNC(sysdate,'dd')函数.函数支持格式有:yyyy MM  dd  hh Mi可以用 select TRUNC(sysdate,'yyyy') fr ...

  2. C#格式化小数位的方法

    C#格式化字符串还是很方便的,之前一直没用过,也就没有缘分了解 Double dValue = 95.12345; int iValue = 10000; string strValue = &quo ...

  3. Arduino 电平转换 升压 OUTPUT与9V/12V元件通信

    原因 网络上有不少怎么让Arduino的5V电平转换成3.3V电平,从而和工作在3.3V下的芯片相互沟通的教程.但是如果想驱动高于5V电压的芯片,就找不到教程了.因此今天我来介绍一种方式,能让Ardu ...

  4. hdu 3478(判断奇环)

    题意:给你一个无向图,问你有没有可能存在一个奇环连接所有的节点. 分析:好久没写博客了,这个好习惯还是要继续保持的!这道题通过转化之后就是问你有没有存在一个奇环连接所有的节点,这里用到的方法是染色法, ...

  5. Yii系列教程(二):功能简介

    1 MVC架构 1.1处理流程 一个Web请求在Yii内部的执行流程如下图所示: 1.2组件角色 组件名 角色与责任 index.php 入口脚本.创建Application的单例对象. applic ...

  6. Android中垃圾回收日志信息

    原因 GC_CONCURRENTfreed 178K, 41% free 3673K/6151K, external 0K/0K, paused 2ms+2msGC_EXPLICITfreed 6K, ...

  7. Android 数独游戏 记录

    Android图形编程基本概念 颜色对象 Color 类 int color = Color.bule    //蓝色 int color = Color.argb(255,255,255,255); ...

  8. ListView蛮好用

    知识点如下: 1. ListView的基本用法 2. ArrayAdapter和SimpleAdapter的用法 3. OnScrollListener 和 OnItemClickListener 4 ...

  9. fopen警告处理方式

    warning C4996: “fopen”被声明为否决的 问题:vs2005中编程时,遇到如下: warning C4996: “fopen”被声明为否决的. 解释:微软的警告,主要是那些都是C库的 ...

  10. [转]一些实用的图表Chart制作工具

    最近工作过程中需要用到前端一些JS框架,看到一篇博文就转过来备份使用,后续会再完善一些材料.   Flot   Flot一个纯javascript绘画库,基于jQuery开发.它能够在客户端根据任何数 ...