I have a UIViewController (controller1) which is displaying some UIbuttons on a UIView. When one of the buttons is clicked I’d like to instantiate a second UIViewController (controller2, which is of an entirely different controller class) which will then create some UIViews programmatically and add these to one of the UIViews being managed by controller1.
So, in controller1 I’d like the following code:
- (void) someButtonPressed: (id)sender
{
ViewController2* controller2 = [ [ ViewController2 alloc ] initWithNibName:nil bundle:nil ];
}
I’d then like to programmatically create the additional UIViews within controller2. Ideally I will not have any further lines of code within controller1 (to add views and suchlike). I’d really like to create all views and add them to the existing views from within the controller2 code.
Can I do this, and how? I’ve tried simply placing the following code in controller2:
- (void)loadView
{
NSLog(@"HPSViewEditorViewController loadView");
}
but it does not get called.
I want to encapsulate the entire UIView hierarchy for controller2 in the controller2 code, and don’t want to ‘clutter up’ controller1 with anything other than the controller2 instantiation.
Thanks.
I would try something like
This could do the trick…