gpt4 book ai didi

ios - 在另一个 UIViewController 中显示一个 UIViewController

转载 作者:行者123 更新时间:2023-12-01 17:15:30 27 4
gpt4 key购买 nike

我正在开发一个应用程序,其中 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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com