我的项目我正在构建 5 个相同的页面,但只有内容发生了变化。因此,在我的AUIViewController中,我可以像TabBarController一样切换页面,并获取我通过SegmentedControl选择的视图。问题是我在GUIViewController中执行的事件和函数没有被调用。它喜欢简单的视图。我怎么能这样呢。
任何答案将不胜感激:)
代码不完全相同,但它是工作。
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;
....
问题是视图控制器不能坚持下去。 为了保留它并允许它控制视图,您需要将其添加为子视图控制器。
添加这个:
UIViewController* first = [viewControllers objectAtIndex:0];
[self.content bringSubviewToFront:first.view];
新东西
[first willMoveToParentViewController:self];
[self addChildViewController:first];
这应该可以解决您的问题。