开发者

Help Creating multiple views with view controllers

开发者 https://www.devze.com 2023-01-04 23:32 出处:网络
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).

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


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!

0

精彩评论

暂无评论...
验证码 换一张
取 消