I have been researching this for a while but can't quite find what I need. I would like to learn how to create a container view with a child view controller programmatically. I'm still fairly new to this and learning the basics, but from what I gather, this used to be done using resuable views and attaching them to child view controllers prior to the container view object being added to the library (right?), I am looking for either a tutorial or example code that shows how to do it from scratch, using xib's, but without any complications, like adding table cells etc... Just the container and the child programmatically. Does that make sense? I'm sure there must be something on S.O. Thanks if you can help.
UPDATE ---------------------------------------------------------------------------------------------------------------------- I have managed to create a child view controller that appears with a UIButton action. Relevant code:
- (IBAction)Pressed:(id)sender {
ChildViewController *childViewController = [[ChildViewController alloc]init];
[self displayContentController:childViewController];
}
- (void) displayContentController: (UIViewController*) content {
[self addChildViewController:content];
content.view.frame = CGRectMake(0, 115, 320, 240);
content.view.backgroundColor = [UIColor redColor];
CATransition *transition = [CATransition animation];
transition.duration = 1;
transition.type = kCATransitionPush;
transition.subtype = kCATransitionFromLeft;
[transition setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
[content.view.layer addAnimation:transition forKey:nil];
[self.view addSubview:content.view];
[content didMoveToParentViewController:self];
}
So that's working fine. I click the button and a red square, child view controller, occupying a small part of the screen appears. What I would like to know is if this is best practice.