今天调试程序遇到个问题,iOS7下在弹出Modal的子界面时,弹出层次不对,键盘和界面被分割在了Window的两侧,导致显示异常
Presenting view controllers on detached view controllers is discouraged <HSRootViewController: 0x15dd248b0>.
由于最上面的窗口是UIWindow,故考虑用addSubView的方式将ViewController.view添加上去了,自己维护ViewController的生存期就好了,但同时也发现了iOS很早就提供的ContainerViewController方式
特此记录下
https://developer.apple.com/library/ios/featuredarticles/ViewControllerPGforiPhoneOS/CreatingCustomContainerViewControllers/CreatingCustomContainerViewControllers.html

Adding and Removing a Child
Listing 14-1 shows a typical implementation that adds a view controller as a child of another view controller. Each numbered step in the listing is described in more detail following the listing.

Listing 14-1 Adding another view controller’s view to the container’s view hierarchy
- (void) displayContentController: (UIViewController*) content;
{
[self addChildViewController:content]; // 1
content.view.frame = [self frameForContentController]; // 2
[self.view addSubview:self.currentClientView];
[content didMoveToParentViewController:self]; // 3
}
Here’s what the code does:

It calls the container’s addChildViewController: method to add the child. Calling the addChildViewController: method also calls the child’s willMoveToParentViewController: method automatically.
It accesses the child’s view property to retrieve the view and adds it to its own view hierarchy. The container sets the child’s size and position before adding the view; containers always choose where the child’s content appears. Although this example does this by explicitly setting the frame, you could also use layout constraints to determine the view’s position.
It explicitly calls the child’s didMoveToParentViewController: method to signal that the operation is complete.
Eventually, you want to be able to remove the child’s view from the view hierarchy. In this case, shown in Listing 14-2, you perform the steps in reverse.

Listing 14-2 Removing another view controller’s view to the container’s view hierarchy
- (void) hideContentController: (UIViewController*) content
{
[content willMoveToParentViewController:nil]; // 1
[content.view removeFromSuperview]; // 2
[content removeFromParentViewController]; // 3
}

Container ViewController初探1的更多相关文章

  1. iOS UIKit:viewController之动画(5)

    当弹出一个view controller时,UIKit提供了一些标准转换动画,并且也支持用户自定义的动画效果. 1 UIView动画 UIView是自带动画实现功能,其中有两种方式实现:        ...

  2. UITabBarController详解

    UITabBarController使用详解 UITabBarController是IOS中很常用的一个viewController,例如系统的闹钟程序,ipod程序等.UITabBarControl ...

  3. 0122——UITabBarController

    UITabBarController是IOS中很常用的一个viewController.UITabBarController通常作为整个程序的rootViewController,而且不能添加到别的c ...

  4. UITabBarController+微博简单模拟1

    UITabBarController是IOS中很常用的一个viewController.UITabBarController通常作为整个程序的rootViewController,而且不能添加到别的c ...

  5. UITabBarController使用详解

    UITabBarController是IOS中很常用的一个viewController,例如系统的闹钟程序,ipod 程序等.UITabBarController通常作为整个程序的rootViewCo ...

  6. IOS开发 UITabBarController

    UITabBarController使用详解 UITabBarController是IOS中很常用的一个viewController,例如系统的闹钟程 序,ipod程序等.UITabBarContro ...

  7. 在UIViewController中获得Container View里的embed viewController的引用

    When you want to use a controller you use the UIStoryboard method instantiateViewControllerWithIdent ...

  8. 【iOS】iOS它Container View获得ViewController

    近期使用Container View来在主View Controller建立自己的子Controller,但是遇到问题.不知道怎样用代码获取Controller View附带的View Control ...

  9. 容器安全拾遗 - Rootless Container初探

    摘要: Docker和Kubernetes已经成为企业IT架构的基础设施,安全容器运行时越来越被关注.近期Docker 19.03中发布了一个重要的特性 “Rootless Container”,在提 ...

随机推荐

  1. FLASH AS 不显示中文

    我修改一个as游戏,发现公告显示不了,整整折腾了2天. flash TextField 汉字不显示,英文会显示,如果是汉字夹杂数字,只把数字显示了,汉字被忽略了.   有人说嵌入字体,网上一搜索,好麻 ...

  2. POJ 3274 Gold Balanced Lineup 哈希,查重 难度:3

    Farmer John's N cows (1 ≤ N ≤ 100,000) share many similarities. In fact, FJ has been able to narrow ...

  3. 在线体验K2 BPM微信审批

    “微信审批”在江湖中传言已久,但很多人依然“只闻其声,未见其人”,这传说中的手感到底有多好?今天,我们就一起来揭开它的真面目吧. 故事发生在上周六傍晚,我接到了加班电话. 晚上21:30终于加完班了, ...

  4. 端午小长假--前端基础学起来03CSS为网页添加样式

    定义:用于定义HTML内容在浏览器内的显示样式,如文字大小,颜色,字体 设置样式:将要设置样式的内容用<span></span>样式括起来,然后再head中设置span < ...

  5. ThinkPHP查询数据与CURD

    一.创建连接 在配置文件中使用如下配置: /* 数据库设置 */ 'DB_TYPE' => 'mysql', // 数据库类型 'DB_HOST' => 'localhost', // 服 ...

  6. xml文件有误

    Unable to start activity ComponentInfo{com.anzi.jmsht.scripturelibrary/com.anzi.jmsht.scripturelibra ...

  7. HDU 1045 - Fire Net (最大独立集)

    题意:给你一个正方形棋盘.每个棋子可以直线攻击,除非隔着石头.现在要求所有棋子都不互相攻击,问最多可以放多少个棋子. 这个题可以用搜索来做.每个棋子考虑放与不放两种情况,然后再判断是否能互相攻击来剪枝 ...

  8. win7下环境搭建

    1.Python下载 https://www.python.org/downloads/windows/ 选择需要安装的版本,我偷懒装的可执行文件. 下载之后双击安装就OK啦,安装过程中有一项偷懒的选 ...

  9. 横竖屏切换时候Activity的生命周期

    1.新建一个Activity,并把各个生命周期打印出来 2.运行Activity,得到如下信息 onCreate-->onStart-->onResume--> 3.按crtl+f1 ...

  10. iOS 调用地图导航

    在IOS6.0系统后,兼容iOS5.0与iOS6.0地图导航,需要分两个步骤 #define SYSTEM_VERSION_LESS_THAN(v) ([[[UIDevice currentDevic ...