0

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?

Community
  • 1
  • 1
jwade502
  • 898
  • 1
  • 9
  • 22
  • What do you want to do? You are add the `_page01ViewController`'s view as a subview of current view. That's why it's overlayed on. – Ryan Aug 25 '14 at 01:19
  • Hello trick14. I want my "rootViewController" to be on top of "page01ViewController" or whichever other pageController is selected. I was under the assumption that this is what would happen. – jwade502 Aug 25 '14 at 01:59
  • Before I was using rootViewController to add pageXXViewController as just a subview without it being a child, but this caused problems and I found out it wasn't recommended by apple, so now I am trying to add them as a child. – jwade502 Aug 25 '14 at 02:03

1 Answers1

0

You may want to user insertSubview:atIndex:. Using an index of 0 will add the view under all the other views. Alternatively you could have a container view for the views of the page view controllers. This container view needs to be added at index 0 in the view of RDJrootPageViewController. The page view controllers views could be added to the afore mentioned container view.

Hope this helps.

gabriel_101
  • 773
  • 3
  • 19
  • That's actually what I have been doing. It works, but when I switch back to that subview, user interaction is disabled on the right 1/4 of the screen. – jwade502 Aug 25 '14 at 03:40
  • What do you mean by switch back? Also your code uses addSubview: not insertSubview:atIndex: as I suggested. – gabriel_101 Aug 25 '14 at 03:45
  • Oh whoops, I copied that from a tutorial. What I mean is that if page01 is loaded as the subview, and then you switch the subview to page02 and then back to page01, then only 3/4 of the screen detects inputs. I think it's because the app I'm making is landscape only and its not rotating something. – jwade502 Aug 25 '14 at 04:17