Xcode 5 模拟器空白白屏
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21973886/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Xcode 5 Simulator Blank White Screen
提问by j.m.g.r
I just installed Xcode 5 (or the latest version) and created a new project. 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. What am I doing wrong?
我刚刚安装了 Xcode 5(或最新版本)并创建了一个新项目。我创建了一个故事板,并添加了一个标签,但是当我在 iPhone 模拟器中打开我的应用程序时,我只会看到一个带有状态栏的空白屏幕。我究竟做错了什么?
I have OS X 10.9.1 Mavericks.
我有 OS X 10.9.1 Mavericks。
采纳答案by Ruiz
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;
回答by nhgrif
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. It should look like this:
您还需要向 AppDelegate.m 添加几行代码。它应该是这样的:
- (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;
}
回答by Reinhard M?nner
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.
您的项目没有视图控制器。创建项目时,您应该从“单一视图项目”开始,它会为您创建一个视图控制器。在这种情况下,您将能够看到您的标签。
回答by Dimitris Bouzikas
EDIT TO FIX:
编辑修复:
If you would like to fix this, remove the property "Main nib file base name." This can be found in the "info" tab of your target.
如果您想修复此问题,请删除“Main nib 文件基本名称”属性。这可以在目标的“信息”选项卡中找到。
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. 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.
似乎在您创建应用程序时,您选择了“空应用程序”模板。然后您从用户界面部分添加了 Storyboard。当您添加标签并运行应用程序时,您看不到“Hello, World”标签,因为应用程序在应用程序启动结束时没有根视图控制器。
Try to create a "Single View Application".
尝试创建一个“单一视图应用程序”。
回答by Joe Mancuso
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> Preferences>Downloads 并下载适当的包。一旦我这样做了,我就运行了模拟器并得到白屏。现在我的白屏顶部有运营商和电池图标。要在模拟器中解决此问题:硬件>设备>9.1,然后重新启动,然后它就可以工作了……
Hope this helped.
希望这有帮助。
SithAdmin
西斯管理员
回答by Rawa K. Ibrahim
Click "Main.storyboard" -> on right prat "Interface Builder Document" uncheck "Use Auto Layout, "Use Size Classes" & "Use as Lunch Screen"
单击“ Main.storyboard”->右侧的“ Interface Builder Document”取消选中“ Use Auto Layout”、“ Use Size Classes”和“ Use as Lunch Screen”
回答by user5946013
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). Stupid but at least, quick to check: create views in Main, not LaunchScreen...
对于一个愚蠢的简单错误,我遇到了同样的问题(空白屏幕)。实际上,元素出现并很快消失。我的错误是我没有在Main.storyboard 中创建(但是LaunchScreen.storyboard 就位,因此它在启动后几秒钟显然消失了)。愚蠢但至少,快速检查:在 Main 中创建视图,而不是 LaunchScreen ......