开发者

Getting black screen when loading navigation controller

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 开发者_如何学Golifecycle


- (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;
}


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

[window makeKeyAndVisible];


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];
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜