本文介绍了“嵌入"另一个内的 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.

添加视图控制器:

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

删除视图控制器:

[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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-25 06:42