我正在开发一个应用程序,其中 UIViewController
( firstViewController ) 包含一些 UILabels
, 一个 UIButton
, 和 UIView
( subview )。 UIView
应该显示 UIViewController
( secondViewController ) 包含一些层。我无法做到这一点。
我该怎么做才能显示 secondViewController 在 内 subview 的 第一 View Controller ?
最佳答案
您应该使用 UIViewController 包含或父/ subview Controller 。您可以阅读详情here .
最基本的版本是:
UIViewController *parentVC = ...
UIViewController *otherVC = ... // it's view will be added as subview
[parentVC addChildViewController:otherVC];
[parentVC.containerView addSubview:otherVC.view]; // containerView is a view where your child view controller should go
[otherVC didMoveToParentViewController:parentVC];
如果只添加其他 View Controller 的 View 作为 subview , subview Controller 将不会收到所有事件。例如,如果您使用此处建议的其他方法(只需将 View 添加为 subview ,仅此而已),您将不会得到
-viewDidAppear:
发送到您的 subview Controller 的消息(和其他)。
关于ios - 在另一个 UIViewController 中显示一个 UIViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25567297/