【问题标题】:Getting black screen when loading navigation controller加载导航控制器时出现黑屏
【发布时间】:2010-07-28 13:58:25
【问题描述】:

下面的代码试图实现一个方法,让我的导航控制器启动到两个不同视图中的一个。问题是每当我的应用程序启动时,我总是会出现黑屏。

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

【问题讨论】:

    标签: iphone objective-c uiview uinavigationcontroller delegates


    【解决方案1】:

    在 if 块之后添加以下行,您将在其中将导航控制器视图添加到窗口:

    [window makeKeyAndVisible];
    

    【讨论】:

    • 另外,请确保您的窗口实例变量设置为 IBOutlet,并且在您的 MainWindow.xib Interface Builder 文件中,文档窗口中的应用程序委托项有一个窗口出口,并且它是连接到同一文档窗口中的窗口对象。
    【解决方案2】:

    如果您遇到黑屏,则说明您的窗口没有加载。

    确保您的 if 事件被调用,并在您将子视图添加到窗口后放置 [window makeKeyAndVisible];

    对我来说很好......

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

    【讨论】:

    • 是的,if 语句正在执行,我只是在添加子视图后替换了 [window makeKeyAndVisible] 并且仍然只是黑色
    • 听起来你有不同的问题。请参阅我更新的帖子.. 对我来说效果很好。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-08
    相关资源
    最近更新 更多