问题
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