简体   繁体   中英

Xcode - UIStoryboard black screen

I am using a UIStoryboard . I created my application empty, and then I added a storyboard. The storyboard is set as the main storyboard in the project settings and also as the 'Main Storyboard file base name' in the Info.plist.

My app delegate simply returns YES without any other code.

My main.m includes this line of code:

return UIApplicationMain(argc, argv, nil, NSStringFromClass([ARGAppDelegate class]));

I get this message in the console:

Application windows are expected to have a root view controller at the end of application launch

My view controller is in the UIStoryboard, as the initial view controller.

Just wondering what I am doing wrong here...

My AppDelegate code:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{        
    return YES;
}

Thats all the code I have, if you are using a storyboard you do not need to create a window right?

Thanks for the help, appreciated!


Update:

I actually changed my AppDelegate code, still does not make a difference:

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

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

    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone" bundle:[NSBundle mainBundle]];
    UIViewController *initViewController = [storyboard instantiateViewControllerWithIdentifier:@"ARGViewControllerID"];

    NSLog(@"%@", initViewController); // Returns a valid ARGViewController object

    [self.window setRootViewController:initViewController];
    [self.window makeKeyAndVisible];
    [self.window makeKeyWindow];

    return YES;
}

When -applicationDidFinishLaunching:withOptions: does not set up a window or storyboard in code, the next place the system looks is in the info.plist for a default XIB or StoryBoard. The 'Default Storyboard' field in your project info is either empty, or pointing at a non-existent .storyboard file. Click your project in the tree then the 'Summary' tab and fill in the field with the name of your storyboard file.

Application windows are expected to have a root view controller at the end of application launch

听起来好像你没有在故事板的开头嵌入导航控制器

Unable to find solution after digging through forums and questions and playing with the code, I switched to xibs. Been happy with it since 4 hours ago when I made the transition. I hope I never have to see another error-filled and hard-to-use storyboard file again!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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