Question

I'm following the advice of this question in order to define my initial view controller at runtime, instead of always being the same based off of the Storyboard property.

This is my didFinishLaunching method:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    UINavigationController *compactNavigationController = [mainStoryboard instantiateViewControllerWithIdentifier:@"CompactNavigationController"];
    self.window.rootViewController = compactNavigationController;
    [self.window makeKeyAndVisible];

    CompactPostsViewController *controller = (CompactPostsViewController *)compactNavigationController.topViewController;
    controller.managedObjectContext = self.managedObjectContext;

    return YES;
}

And I've unchecked "Is Initial View Controller" in my Storyboard, and I've removed "Main" from the default Storyboard in my app's info.

But when I launch the app I get a completely black screen. What am I doing wrong?

Was it helpful?

Solution

Your window is nil because you never created it. You need to add this line,

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

The window is created for you when you have the "Main storyboard base name" entry in your info.plist, but if you remove that, then you have to create the window yourself.

OTHER TIPS

check your linkings in your storyboard(by right click on the tableview controller).This happens mostly when you not linked your tableview controller properly.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top