“嵌入"UIViewController在另一个 [英] "Embed" UIViewController within another

查看:62
本文介绍了“嵌入"UIViewController在另一个的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个UIViewController(DetailViewController),它由顶部的导航栏和覆盖屏幕其余部分的UIView组成.可以使用除DetailViewController之外的UIViewController来控制UIView吗?

I have a UIViewController (DetailViewController) consisting of a navigation bar on the top and a UIView covering the rest of the screen. Is it possible to control the UIView with a UIViewController other than DetailViewController?

推荐答案

您可以执行此操作,但一定不要忘记调用Apple嵌入UIViewControllers所需的方法.否则,操作系统将不会调用您的视图控制器来处理某些事件.

You can do this, but you must not forget to call Apple's required methods for embedding UIViewControllers. Otherwise, your view controller will not get called by the OS to handle certain events.

要添加视图控制器,请执行以下操作:

To add the view controller:

[self addChildViewController:childViewController];                 
[self.view addSubview:childViewController.view];
[childViewController didMoveToParentViewController:self];

要删除视图控制器,请执行以下操作:

To remove the view controller:

[childViewController willMoveToParentViewController:nil];  
[childViewController.view removeFromSuperview];            
[childViewController removeFromParentViewController];

相关文档:

  • Implementing a Container View Controller in the UIViewController Class Reference
  • Implementing a Container View Controller in the View Controller Programming Guide for iOS

有关更多信息,请参见此问题.

See this question for more information.

这篇关于“嵌入"UIViewController在另一个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆