简体   繁体   English

Xcode 5模拟器空白屏幕

[英]Xcode 5 Simulator Blank White Screen

I just installed Xcode 5 (or the latest version) and created a new project. 我刚刚安装了Xcode 5(或最新版本)并创建了一个新项目。 I created a storyboard, and added a label, but when I open my application in the iPhone simulator, I simply get a blank white screen with a status bar. 我创建了一个故事板,并添加了一个标签,但是当我在iPhone模拟器中打开我的应用程序时,我只是得到一个带有状态栏的空白屏幕。 What am I doing wrong? 我究竟做错了什么?

I have OS X 10.9.1 Mavericks. 我有OS X 10.9.1小牛队。

在此输入图像描述

I know I'm quite late to this, but the solution to this problem is quite simple and is even shown in one of Apple's own tutorials . 我知道我已经很晚了,但是这个问题的解决方案非常简单,甚至可以在Apple自己的教程中看到

Assuming that you started off with an "Empty Project", created a storyboard from scratch, and set your storyboard as the main interface, you need to remove a few lines in the first method of AppDelegate.m. 假设您从“空项目”开始,从头开始创建故事板,并将故事板设置为主界面,则需要在AppDelegate.m的第一个方法中删除几行。

This: 这个:

    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;

Should become just this: 应该变成这样:

    return YES;

I'm going to assume that you started an empty project, which doesn't start with a storyboard and then after creating the project, you created a storyboard file. 我将假设您启动了一个空项目,该项目不是以故事板开头,然后在创建项目后创建了一个故事板文件。

You have to tell your app which storyboard to load. 你必须告诉你的应用程序要加载哪个故事板。

In the below screen shot, you'll want to click the "Main Interface" drop down and select the storyboard you want to start your app with. 在下面的屏幕截图中,您需要单击“主界面”下拉列表,然后选择要启动应用程序的故事板。

在此输入图像描述

This is the "Deployment Info" section of the "General" tab of your targets. 这是目标“常规”选项卡的“部署信息”部分。


You also need to add a couple lines of code to your AppDelegate.m. 您还需要向AppDelegate.m添加几行代码。 It should look like this: 它应该如下所示:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"YOUR_STORYBOARD_NAME" bundle:[NSBundle mainBundle]];
    UIViewController *vc =[storyboard instantiateInitialViewController];
    self.window.rootViewController = vc;
    [self.window makeKeyAndVisible];
    return YES;
}

Your project does not have a view controller. 您的项目没有视图控制器。 When you created your project, you should have started with a "Single view project", which would have created a view controller for you. 在创建项目时,您应该已经开始使用“单视图项目”,这将为您创建一个视图控制器。 In that case, you would have been able to see your label. 在这种情况下,您可以看到您的标签。

EDIT TO FIX: 编辑修复:

If you would like to fix this, remove the property "Main nib file base name." 如果要修复此问题,请删除属性“主nib文件基本名称”。 This can be found in the "info" tab of your target. 这可以在目标的“信息”标签中找到。

在此输入图像描述

The problem: 问题:

It seems that when you created your application, you selected the "Empty Application" template. 您似乎在创建应用程序时选择了“空应用程序”模板。 Then you added the Storyboard from the user interface section. 然后,您从用户界面部分添加了Storyboard。 When you added the label and ran the application, you can't see the "Hello, World" label, because the application does not have a root view controller at the end of the application launch. 添加标签并运行应用程序时,您无法看到“Hello,World”标签,因为应用程序在应用程序启动结束时没有根视图控制器。

Try to create a "Single View Application". 尝试创建“单一视图应用程序”。

Just wanted to chime in on this thread and shed some light on the matter. 只想在这个帖子上插话,并对此事进行一些说明。 I myself was working on my first project and was getting the white screen. 我自己正在研究我的第一个项目并且正在获得白色屏幕。 I found this article and it helped and it didn't, but this is what worked for me. 我找到了这篇文章并且它没有帮助,但它没有,但这对我有用。 Everyone is right on what they posted, but I was running 9.2 simulator when in fact I only have 9.1 installed (if you need help with this go to Xcode> Preferences>Downloads and download the appropriate package. Once I did that I ran the simulator and got the white screen. Now my white screen had the carrier and batt icon at the top. To fix this issue in Simulator: Hardware>Device>9.1 and a reboot occurred and then it works... 每个人都对他们发布的内容是正确的,但我运行9.2模拟器实际上我只安装了9.1(如果你需要帮助,请转到Xcode>首选项>下载并下载相应的包。一旦我这样做,我运行了模拟器现在我的白色屏幕顶部有载体和batt图标。要在模拟器中修复此问题:硬件>设备> 9.1并重新启动,然后它可以工作......

Hope this helped. 希望这有帮助。

SithAdmin SithAdmin

I had the same issue (blank screen) for a stupid simple error. 我有一个愚蠢的简单错误的相同问题(空白屏幕)。 Actually, the elements appeared and soon fade away. 实际上,元素出现并很快消失。 My mistake was that I was not creating in in Main .storyboard (but LaunchScreen .storyboard in place, so that it obviously disappeared couple of seconds after start). 我的错误是我没有在Main .storyboard中创建(但是启动时屏幕上有LaunchScreen。 存储板,所以它在启动后几秒钟就会消失)。 Stupid but at least, quick to check: create views in Main, not LaunchScreen... 愚蠢但至少快速检查:在Main中创建视图,而不是LaunchScreen ...

单击右侧的“ Main.storyboard ” - >“ Interface Builder Document ”取消选中“ Use Auto Layout” ,“ Use Size Classes ”和“ Use as Lunch Screen

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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