iOS Application launch black screen, UINavigationController, Nib, RootViewController

三世轮回 提交于 2019-12-02 15:10:08

问题


I've got the following app, whose RootViewController is named TopicsViewController.

When I run it, there aren't any errors or breaks but the screen is black. No table, populated or empty, just a black screen. Not sure which of the following is happening:

  • Is there something wrong with my application didFinishLaunchingWithOptions method in relation to a parser initlizing in it?
  • Is it something to do with my nib file for the TopicsViewController?

I can show more code from my TopicsViewController class if needed.

- (BOOL)application:(UIApplication *)application
    didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
///////////////////////////////////////////

***initializing code for parser which populates TopicsViewController (not shown to save space)*****

///////////////////////////////////////////
UIViewController *rootController =
[[TopicsViewController alloc]
 initWithNibName:@"TopicsViewController" bundle:nil];

navController = [[UINavigationController alloc]
                 initWithRootViewController:rootController];

self.window = [[UIWindow alloc]
               initWithFrame:[[UIScreen mainScreen] bounds]];
[self.window addSubview:navController.view];
[self.window makeKeyAndVisible];
return YES; 
}

回答1:


Instead of:

[self.window addSubview:navController.view];

Write:

self.window.rootViewController = self.navController;


来源:https://stackoverflow.com/questions/14487024/ios-application-launch-black-screen-uinavigationcontroller-nib-rootviewcontro

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!