I am looking for the same answer. Why is this such a difficult thing to do? I have two views and cooresponding controllers..and the rootViewController files.
HomePageView.xib, HomePageViewController.h and .m
EssentialsPageView.xib, EssentialsPageViewController.h and .m
I have a button on HomePage and of course the rootViewController class displays this page just fine by enacting the 'viewDidLoad' method….
- (void)viewDidLoad
{
HomePageViewController *viewController = [[HomePageViewController alloc]
initWithNibName:@”HomePageView” bundle:nil];
self.homeViewController = viewController;
[viewController release];
[self.view insertSubview:homeViewController.view atIndex:1];
}
I also tested the following code on the file HomePageViewController.m …
-(IBAction) essentialsButton
{
NSLog(@”essentials button pressed”);
RootViewController *go = [[RootViewController alloc] init];
go.loadEssentialsView;
[go release];
}
and it fires the following method on the rootViewController.m file…..
-(void) loadEssentialsView
{
NSLog(@”loadEssentialsView method is firing”);
EssentialsViewController *thisviewController = [[EssentialsViewController alloc]
initWithNibName:@”EssentialsPageView” bundle:nil];
self.essentialsViewController = thisviewController;
[thisviewController release];
[self.view insertSubview: essentialsViewController.view atIndex:2];
[self.view exchangeSubviewAtIndex:1 withSubviewAtIndex:2];
}
Please remember that RootViewController is an subclass of UIViewController, not UINaviagationController.I don't want to use a navigation controller because of the viewing requirements.
I can only think there must be some conflict with the HomeView that is already loaded. I know I can't use a 'removeFromSuperView' method while the view is being displayed. Is there a problem with 'insertSubView'??? I am so confused….