views:

53

answers:

2

The following code below is attempting to implement a method where my navigation controller launches to on e of two different views. The problem is that I keep getting a black screen whenever my application launches.

#import "SugarCRMReleaseOneAppDelegate.h"
#import "SettingsViewController.h"
#import "ModuleViewController.h"

@implementation SugarCRMReleaseOneAppDelegate

@synthesize window;
@synthesize navigationController;


#pragma mark -
#pragma mark Application lifecycle


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    
    // Override point for customization after app launch   

    NSString *a2 = [[NSString alloc] init];
    a2 = [[NSUserDefaults standardUserDefaults] objectForKey:@"savedUsername"];
    NSString *b2 = [[NSString alloc] init];
    b2 = [[NSUserDefaults standardUserDefaults] objectForKey:@"savedPassword"];

    [window makeKeyAndVisible];
    if(a2 == nil && b2 == nil) {
        SettingsViewController *viewController1 = [[SettingsViewController alloc] initWithNibName:@"SettingsViewController" bundle:nil];
        [navigationController initWithRootViewController:viewController1];
        [window addSubview:[navigationController view]];
        [viewController1 release];
    }
    else {
        ModuleViewController *viewController2 = [[ModuleViewController alloc] initWithNibName:@"ModuleViewController" bundle:nil];
        [navigationController initWithRootViewController:viewController2];
        [window addSubview:[navigationController view]];
        [viewController2 release];
    }

    [UIApplication sharedApplication].idleTimerDisabled=YES;
    return YES;
}
A: 

If you are getting a black screen, then your window is not getting loaded.

Make sure your if events are being called and also place [window makeKeyAndVisible]; after you add your subviews to the window.

Works fine for me...

int i = 0;

if(i == 1) {
    VideosViewController *viewController1 = [[VideosViewController alloc] initWithNibName:@"VideosViewController" bundle:nil];
    UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController1];
    [window addSubview:[navigationController view]];

    [window makeKeyAndVisible];

    [viewController1 release];
}
else {
    Videos2ViewController *viewController2 = [[Videos2ViewController alloc] initWithNibName:@"Videos2ViewController" bundle:nil];
    UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController2];
    [window addSubview:[navigationController view]];

    [window makeKeyAndVisible];

    [viewController2 release];
}
iWasRobbed
Ya the if statement is being executed and i just replaced the [window makeKeyAndVisible] after adding the subviews and still just black
Chris
You added them within the `if` statement and still no show?
iWasRobbed
Yes that is correct
Chris
Sounds like you have a different problem then. See my updated post.. that worked just fine for me.
iWasRobbed
+1  A: 

Add the following line right after the if block where you are adding the nav controller view to the window:

[window makeKeyAndVisible];
BP
just tried it and got the same result
Chris
If you uncomment out the viewDidLoad (unless you are already using them) for each of your views, and you put breakpoints in each of the possible views to load, does it hit the breakpoint?
BP
Also, make sure that your window instance variable is set up as an IBOutlet, and in your MainWindow.xib Interface Builder file, your app delegate item in the document window has a window outlet and that it is wired up to the window object in the same document window.
BP