views:

81

answers:

1

Ok here is what i am trying to do. In my root view controller I have the main view and then inside that view, i have three additional views. (note this is for the ipad).

Here is what I want to do. When the root view loads i want it to load the other three views as well and all have their own view controller.

Here is what I have attempted to far.

In my root controller xib I put in three view controllers and deleted their views. I then plugged into each controller view slot the views i have laid out within my root controller view. I also plugged in the view controller refrences with the ones i set up in rootcontroller.h

In my rootcontroller.m under the viewdidload i tried setting for example.

theViewController = [[ViewController alloc] initWithNibName:@"AView" bundle:[NSBundle mainBundle]];

but to no avail that did not work

A: 

ViewControllers where desgined to use the entire screen, so this case should not happen. However, is very common that you need some complex user interactions inside your views (specially in iPad) to consider the use of a viewcontroller with some child viewcontrollers that encapsulate this logic as you explained above.

What I suggest you is to implement it by code. You could use something like:

-(void) viewDidLoad {

//Create view controllers viewController1_ = [[ViewController alloc] initWithNibName:@"View1" andBundle:nil]; viewController2_ = [[ViewController alloc] initWithNibName:@"View1" andBundle:nil]; viewController3_ = [[ViewController alloc] initWithNibName:@"View1" andBundle:nil];

//Add the views to your main view [self.view addSubview:viewController_1.view]; [self.view addSubview:viewController_2.view]; [self.view addSubview:viewController_3.view];

//TODO: Maybe set the appropiate frames?

}

Becareful with the event bypass. As you are embebing your secondary viewcontrollers into the main one, none of the standard events will be passed down to your child controlles (for example: viewWillAppear, shouldAutorotate,... will not be received by your child controllers). Remember to bypass them explecitly if you need them in your child viewcontrollers.

If your views are not correctly created using IB, check that you dont have problems with these event bypass problem.

Hope that helps!

Angel García Olloqui
Thank you for your input. So instead of establishing these view controllers in the xib, i should do it through code. And if I adjust the frame they should look right.OK I can give this a try, cause as of now my work around was to put a table view inside a view which is inside my main view. Then call that controller through a modal view, with a style of current context. And it works but i feel like it is a hack and is doing something it is not intended for. I do need all the methods of the child views to be passed and also table fuctionallity? How do i go about doing this?
Matt
Figured it out and your solution works thank you!
Matt