该程序在调试器中与以下内容和“lldb”崩溃 - Swift 4

时间:2018-05-07 01:20:09

标签: swift xcode debugging lldb

这是一个程序代码,其行为如下:当用户按下按钮时,名为“The Character”的UIImage会上升(它改变其y轴)。但是当我运行程序时,它不会崩溃但是当我按下名为“characterGoesUp”的按钮时,程序崩溃了,我在调试器中得到以下内容:“lldb”。为什么? 代码:

import UIKit

class ViewController: UIViewController {


@IBOutlet weak var TheCharacter: UIImageView!

@IBAction func characterGoesUp(_ sender: Any) {
    let xPos = TheCharacter.frame.origin.x

    let yPos = TheCharacter.frame.origin.y - 225

    let heightCharacter = TheCharacter.frame.size.height
    let widthCharacter = TheCharacter.frame.size.width

    UIView.animate(withDuration: 1.0, animations: {
        self.TheCharacter.frame = CGRect(x: xPos, y: yPos, width: widthCharacter, height: heightCharacter)
    }) { (finished) in

    }

}
override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.
}


}

Xcode版本:9.3

编辑: 错误是这样的: “线程1:致命错误:在打开可选值时意外发现nil”

1 个答案:

答案 0 :(得分:0)

您的问题是imageView public IEnumerable<simpletest> NodesAtDepth(int depth) { if (depth <= 0 ) yield return this; else if (depth > 1) { if (this.Children != null) foreach (simpletest child in this.Children) foreach (simpletest element in child.NodesAtDepth(depth - 1)) yield return element; } else { if (this.Children != null) foreach (simpletest element in this.Children) yield return element; } } 未正确连接到IB,并且由于TheCharacter

!

在声明中崩溃,因为它是零

//

打开助手编辑器并从图像拖动到ViewController的imageView

enter image description here