Reputation: 1348
my project i'm building 5 same page but only the content change. So in my AUIViewController i can switch page like TabBarController and get the view that i selected by the SegmentedControl. The problem is that event and function that i do in GUIViewController isn't call. it like simple view. How can i sovle that.
any answers will be appreciated :)
code are not exactly the same but it's work.
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;
....
Upvotes: 0
Views: 308
Reputation: 1767
The problem is that the viewController doesn't stick around. In order to keep it and allow it to control the view, you need to add it as a childViewController.
Add this:
UIViewController* first = [viewControllers objectAtIndex:0];
[self.content bringSubviewToFront:first.view];
// New stuff
[first willMoveToParentViewController:self];
[self addChildViewController:first];
That should solve your issue.
Upvotes: 1