gpt4 book ai didi

ios - 从另一个 UIViewController 和他的事件复制 UIView

转载 作者:行者123 更新时间:2023-11-29 03:12:59 24 4
gpt4 key购买 nike

我的项目正在构建 5 个相同的页面,但只有内容发生变化。因此,在我的 AUIViewController 中,我可以切换页面如 TabBarController 并获取我通过 SegmentedControl 选择的 View 。问题是我在 GUIViewController 中执行的事件和函数未被调用。它喜欢简单的 View 。我该如何解决。

任何答案将不胜感激:)

代码不完全相同,但可以正常工作。

AUIViewController.m :

-(void) viewDidLoad
{
...
...
for (.. i <= 5 ..) {
UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Main" bundle:NULL]
UIViewController *g = [sb instantiateViewControllerWithIdentifier:@"GController"];
[self.content addSubView:a.view]
[slef.viewControllers addObject:g]
}
UIViewController* first = [viewControllers objectAtIndex:0];
[self.content bringSubviewToFront:first.view];
}

AUIViewController.h :

....
@proprety (strong,nonatomic) UIView content; // it's a containair
@proprety NsMuableArray* controllerView;
....

最佳答案

问题是 viewController 没有固定下来。为了保留它并允许它控制 View ,您需要将它添加为 childViewController。

添加这个:

UIViewController* first =  [viewControllers objectAtIndex:0];
[self.content bringSubviewToFront:first.view];

//新东西

[first willMoveToParentViewController:self];
[self addChildViewController:first];

这应该可以解决您的问题。

关于ios - 从另一个 UIViewController 和他的事件复制 UIView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22001697/

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