简体   繁体   English

从xib加载iOS黑屏

[英]iOS Black screen while loading from xib

I am trying to load application with .xib file. 我正在尝试使用.xib文件加载应用程序。 I don't know why my screen turns black... 我不知道为什么我的屏幕会变黑...

My AppDelegate code: 我的AppDelegate代码:

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

    MainViewController *mainViewController = [[MainViewController alloc] initWithNibName:@"MainViewController" bundle:nil];

    self.window.rootViewController = mainViewController;

    [self.window makeKeyAndVisible];

    return YES;
}

When you build your application manually (not using a storyboard), you need to create your own window. 手动构建应用程序(不使用故事板)时,需要创建自己的窗口。

self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.rootViewController = mainViewController;
[self.window makeKeyAndVisible];

When using Storyboards, the application does this whole process before calling application:didFinishLaunchingWithOptions: . 使用Storyboard时,应用程序在调用application:didFinishLaunchingWithOptions:之前完成整个过程。 That's why UIApplicationDelegate.window was added in iOS 5 and many modern tutorials don't show you the setup steps. 这就是UIApplicationDelegate.window在iOS 5中添加的原因,许多现代教程都没有向您展示设置步骤。 Before then it was just common practice to have that property. 在此之前,拥有该财产只是通常的做法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM