I have a UIViewController
called RootViewController
and A UIViewController
called NewsViewController
. I want to show NewsViewController
inside a UIView
(the UIView
is just a part of the screen) I created inside RootViewController
. I'm using StoryBoard and my app needs to support iOS 5 (so I can't use embedded segues aka Containers from the IB)
RootViewController code:
- (void)viewDidLoad
{
[super viewDidLoad];
NewsViewController *news = [[NewsViewController alloc]init];
news.view.frame = self.newsSection.bounds;
[self.newsSection addSubview:news.view];
[self addChildViewController:news];
// Do any additional setup after loading the view.
}
I also connected both UIViewControllers with a segue. The UIView newsSection will stay empty. What Am I doing wrong?
Edit:
This works for me, is that the right approach?
- (void)viewDidLoad
{
[super viewDidLoad];
UIStoryboard* storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
NewsViewController *news = [storyboard instantiateViewControllerWithIdentifier:@"NewsViewControllerID"];
news.view.frame = self.newsSection.bounds;
[self.newsSection addSubview:news.view];
[self addChildViewController:news];
[news didMoveToParentViewController:self];
}