简体   繁体   中英

iOS Simulator shows either blank black or white screen

I am running one project with no problems at all, but the second won't show up in iOS Simulator. What it does show depends on what's in my didFinishLaunchingWithOptions method in AppDelegate.m .

Gives black screen:

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

Gives white screen:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    return YES;
}

Any ideas for a fix?

If you use .xib:

In first case you see black screen because you even not created window, in the second - you created white window, but without root controller.

You need to specify rootViewController of the window:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    // Your don't need specify window color if you add root controller, you will not see window because root controller will be above window.
    //self.window.backgroundColor = [UIColor whiteColor];

    self.window.rootViewController = [YourViewController new];

    [self.window makeKeyAndVisible];
    return YES;
}

If you use storyboard leave the first example:

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

And make sure that in proj file you specified the main storyboard: 在此输入图像描述

Also make sure that you set one of the view controllers in the storyboard as an initial: 在此输入图像描述

I'm using XCode V7.3.1 on El Capitan, and I got the simulator with the white screen on even the simplest of single view applications. I figured the controls were being displayed off screen but didn't know why.

I fixed it by scaling the simulator window down to less than 100%. On the simulator menubar, go to Window->Scale and pick 50 or 75%, and for me, the controls showed up properly laid out.

If you chosen "use storyboard", it is normal that you have

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

at this point, when you run it, you should see the ViewController's view of the default view controller (if you didn't mess with the storyboard file).

Try to click on your storyboard, select the controller clicking on the first icon on the black bar under it, and then select the identity inspector (3rd button on the right side panel), check that the custom class is the class of the existing ViewController that Xcode created for you, making sure that it is the initial controller

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