Hi there,
Thanks in advance for any help. I've searched everywhere for an answer to this and simply can't figure it out. I'm very new to all this so I'm sure this is probably really basic and I'm just missing something obvious.
Basically, I'm building a multi-view application, with an initial view containing 2 buttons. Tapping either button should load up a new view, but I can't get this to work at all.
I have several classes:
My_ApplicationAppDelegate
SwitchViewController
SplashScreenViewController
ScreenOneViewController
ScreenTwoViewController
SwitchViewController loads the SplashScreenViewController class.
SplashScreenViewController is associated with a NIB file containing the 2 buttons. Clicking button 1 should load screen 1 and clicking button 2 should load screen 2.
SplashScreenViewController.m contains 2 functions (one for each button press), which in turn call the functions to do the actual view switching, located in SwitchViewController.
The problem I have is that I can get these functions to run fine (if I printf I can see the output in the console) but I can't get them to actually remove the splash screen view and replace it with screen one or screen two.
The idea of having an overall SwitchViewController class to handle all my screen changes seemed sensible (maybe I'm wrong though), so I'm guessing it's just that I'm not removing the right view maybe? But I get no error messages.
My code for the functions called by the button clicks and the subsequent functions they call are below. I've double checked all the nibs have all the proper connections etc...
Button tap code located in SplashScreenController.m
Code:
- (IBAction)postButtonPressed:(id)sender {
SwitchViewController *switchViewController = [[SwitchViewController alloc] init];
// call function in the SwitchViewController class
[switchViewController switchToScreenOneView];
[SwitchViewController release];
}
Code located in SwitchViewController.m
Code:
#import "SwitchViewController.h"
#import "SplashScreenViewController.h"
#import "ScreenOneViewController.h"
#import "ScreenTwoViewController.h"
@implementation SwitchViewController
@synthesize splashScreenViewController;
@synthesize screenOneViewController;
@synthesize screenTwoViewController;
- (void) switchToScreenOneView {
// remove the current view
[splashScreenViewController.view removeFromSuperview];
// load the new view
ScreenOneViewController *screenOneController = [[ScreenOneViewController alloc] initWithNibName:@"ScreenOneView" bundle:nil];
self.screenOneViewController = screenOneController;
[self.view insertSubView:screenOneViewController.view atIndex:0];
[screenOneController release];
}
Thanks again for any help anyone can offer. It would be greatly appreciated.
All the best,
Ian