I have what is a seemingly simple problem but I cannot find a solution! I have a subclass of UIViewController that is my root view controller, and ten different other UIViewcontrollers that I want to load in as child view controllers when called (one at a time, not all ten on screen at once.)
The root controller has a few buttons whose actions call the respective code to bring up a child view controller. The root view controller is loaded first by the nib and I want to instantiate it with page01ViewController as the first child. But whenever I call the following code, the child view controller is overlayed on top of my rootViewController, hiding all of the control buttons in my root controller!
// RDJrootPageViewController.m
#import "RDJrootPageViewController.h"
#import "RDJhomeScreenViewController.h"
#import "RDJpage01ViewController.h"
#import "RDJpage02ViewController.h"
#import "RDJpage03ViewController.h"
#import "RDJpage04ViewController.h"
#import "RDJpage05ViewController.h"
#import "RDJpage06ViewController.h"
#import "RDJpage07ViewController.h"
#import "RDJpage08ViewController.h"
#import "RDJpage09ViewController.h"
#import "RDJpage10ViewController.h"
@interface RDJrootPageViewController ()
@property (retain, nonatomic) RDJhomeScreenViewController *homeScreenViewController;
@property (retain, nonatomic) RDJpage01ViewController *page01ViewController;
@property (retain, nonatomic) RDJpage02ViewController *page02ViewController;
@property (retain, nonatomic) RDJpage03ViewController *page03ViewController;
@property (retain, nonatomic) RDJpage04ViewController *page04ViewController;
@property (retain, nonatomic) RDJpage05ViewController *page05ViewController;
@property (retain, nonatomic) RDJpage06ViewController *page06ViewController;
@property (retain, nonatomic) RDJpage07ViewController *page07ViewController;
@property (retain, nonatomic) RDJpage08ViewController *page08ViewController;
@property (retain, nonatomic) RDJpage09ViewController *page09ViewController;
@property (retain, nonatomic) RDJpage10ViewController *page10ViewController;
@end
@implementation RDJrootPageViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
currentPage = 1;
self.page01ViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"page01"];
[_page01ViewController.view setFrame:CGRectMake(0, 0, 1024, 768)];
[self addChildViewController:_page01ViewController];
[self.view addSubview:_page01ViewController.view];
[_page01ViewController didMoveToParentViewController:self];
[self.view setUserInteractionEnabled:YES];
}
My problem is similar to the one asked here, but no solution was ever identified:
Return from Child View Controller to Container
Every tutorial I find has the same setup: make your new VC, add it as a childView to self, then add that as a subview to your root view, but it dosen't work.
Anyone know the right way to do this?