简体   繁体   English

Xcode 6.0.1-卡在启动屏幕xib上或仅显示黑屏。 错误无处不在

[英]Xcode 6.0.1 - Either gets stuck on the Launch Screen xib or just shows a black screen. Error came out of nowhere

I have an iOS app that I'm building in Xcode 6.0.1 on Yosemite 10.10 . 我有一个iOS应用程序,我正在Yosemite 10.10上的Xcode 6.0.1构建。 I've been working on this for a couple weeks now and all of the sudden today everything has gone wrong. 我已经为此工作了两个星期,而今天突然之间,所有事情都出了问题。

When I first started the project, I just deleted the Launch Screen xib that's auto generated by Xcode, and then I set my initial view controller in Storyboard and its been working fine. 当我第一次启动该项目时,我只是删除了Xcode自动生成的启动屏幕xib,然后在Storyboard中设置了我的初始视图控制器,并且该控制器工作正常。

For some reason today, everything changed. 今天由于某种原因,一切都改变了。 Now, if I try to run the app on my iPhone 4s or any of the simulators, it just shows a black screen. 现在,如果我尝试在iPhone 4s或任何模拟器上运行该应用程序,它将仅显示黑屏。

So I figured maybe I could fix it by adding a launch screen. 所以我想也许可以通过添加启动屏幕来修复它。 I created a xib file called Launch Screen, and set it as the "Launch Screen File" in the target's general settings. 我创建了一个名为“启动屏幕”的xib文件,并在目标的常规设置中将其设置为“启动屏幕文件”。

Now when I run the app, it shows the Launch Screen, but it gets stuck there and never moves to the initial view controller. 现在,当我运行该应用程序时,它会显示启动屏幕,但它会卡在此处,并且永远不会移动到初始视图控制器。 Then it just times out and Xcode gives me the following prompt: 然后它只是超时,Xcode给我以下提示:

 Lost connection to [insert device name here] 

I had this happen due to bad code in the viewDidLoad of my initial view controller that neither the compiler nor the static analyzer caught. 我发生这种情况是由于初始视图控制器的viewDidLoad的错误代码导致编译器和静态分析器均未捕获。 I am using Swift. 我正在使用Swift。 This code was the culprit: 这段代码是罪魁祸首:

var image = UIImage(named: "LoginUsernameIcon")
var iconImageView = UIImageView(frame: CGRectMake(
    0.0, 0.0, 26.0, 26.0
))
iconImageView.image = image
usernameField.leftView = iconImageView

image = UIImage(named: "LoginPasswordIcon")
iconImageView.image = image
passwordField.leftView = iconImageView

Reinitializing iconImageView allowed my app to launch again: 重新初始化iconImageView允许我的应用再次启动:

var image = UIImage(named: "LoginUsernameIcon")
var iconImageView = UIImageView(frame: CGRectMake(
    0.0, 0.0, 26.0, 26.0
))
iconImageView.image = image
usernameField.leftView = iconImageView

image = UIImage(named: "LoginPasswordIcon")
iconImageView = UIImageView(frame: CGRectMake(   // <<<<<
    0.0, 0.0, 26.0, 26.0                         // <<<<<
))                                               // <<<<<
iconImageView.image = image
passwordField.leftView = iconImageView

So FWIW, I would double check your code to see if you have anything that looks off-kilter. 因此,FWIW,我将仔细检查您的代码,以查看是否有任何看起来很奇怪的东西。 I am not sure why an error is not produced by Xcode. 我不确定为什么Xcode不会产生错误。

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

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