FYI I'm programming in objective-C but anyone might be able to help. I've been sitting here for the past two hours trying to figure out what the problem is and I've done everything I know to debug this simple little coding problem. Check out the code below and I will explain. In the application, it starts out with MainScreenViewController. My application gives the user two choices...pick a "master" button or "worker" button (basic client-server model). Based upon the user's choice, the application is then supposed to load another view (either MasterViewController or WorkerViewController). Now, when I run the application, if you have followed the print commands and hypothetically pick the "master" button, then in my program, it prints out "masterButtonPressed - Stage 1" and "masterButtonPressed - Stage 2" but nothing else. The view doesn't change either which tells me the problem lies within the code in the AppDelegate section. After I put the print commands in there and run the application, it still does not print the two statements I have in the AppDelegate section. I do have the correct #import statements in the correct files, I just didn't include them here because that takes up useless space. I can compile the code fine with no error and no warnings. Theoretically, what I should be seeing in the console are four lines when I press the "master" button and they are (in order) - "masterButtonPressed - Stage 1", " changeToMaster - Stage 1", "changeToMaster - Stage 2", and "masterButtonPressed - Stage 2". Can someone point out where I've gone wrong? Like I said the view never changes when press the "master" button. Thanks for your help!
MainScreenViewController.h
@interface MainScreenViewController : UIViewController {
}
-(IBAction)masterButtonPressed;
-(IBAction)workerButtonPressed;
@end
MainScreenViewController.m
@implementation MainScreenViewController
-(IBAction)masterButtonPressed {
NSLog(@"masterButtonPressed - Stage 1");
[ErwinAppDelegate changeToMaster];
NSLog(@"masterButtonPressed - Stage 2");
}
-(IBAction)workerButtonPressed {
NSLog(@"workerButtonPressed - Stage 1");
[ErwinAppDelegate changeToWorker];
NSLog(@"workerButtonPressed - Stage 2");
}
@end
ErwinAppDelegate.h
@class MainScreenViewController, MasterViewController, WorkerViewController;
@interface ErwinAppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
MainScreenViewController *mainScreenViewController;
MasterViewController *masterViewController;
WorkerViewController *workerViewController;
}
@property(nonatomic, retain) IBOutlet UIWindow *window;
@property(nonatomic, retain) IBOutlet MainScreenViewController *mainScreenViewController;
@property(nonatomic, retain) IBOutlet MasterViewController *masterViewController;
@property(nonatomic, retain) IBOutlet WorkerViewController *workerViewController;
-(void)changeToMaster;
-(void)changeToWorker;
@end
ErwinAppDelegate.m
@implementation ErwinAppDelegate
@synthesize window, mainScreenViewController, masterViewController, workerViewController;
- (void)applicationDidFinishLaunching:(UIApplication *)application {
// Override point for customization after application launch
[window addSubview:mainScreenViewController.view];
[window addSubview:masterViewController.view];
[window addSubview:workerViewController.view];
[window makeKeyAndVisible];
// Bring first view up front
[window bringSubviewToFront:mainScreenViewController.view];
}
-(void)changeToMaster {
NSLog(@"changeToMaster - Stage 1");
[window bringSubviewToFront:masterViewController.view];
NSLog(@"changeToMaster - Stage 2");
}
-(void)changeToWorker {
NSLog(@"changeToWorker - Stage 1");
[window bringSubviewToFront:workerViewController.view];
NSLog(@"changeToWorker - Stage 2");
}
@end