我使用故事板将UILabel连接到我的VC,确实生成了弱变量但连接到故事板参考。无论如何,每当我尝试打开它时,我得到的只是零值。让我最困惑的是我能够通过其他方法访问它。我已经安全地解开了它,它避免了编译器错误,但是没有解决我的问题。
编译器消息是:致命错误:在解包可选值时意外发现nil
以下是一些代码:
@IBOutlet weak var linesLeftCountLabel: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
skView = SKView(frame: sceneView.frame)
skView.multipleTouchEnabled = false
//Create and configure the scene.
scene = LogoRefactoryScene(size: skView.bounds.size)
scene.scaleMode = .AspectFill
skView.presentScene(scene)
tapGesture = UITapGestureRecognizer(target: self, action: "eraseLine:")
tapGesture.delegate = self
view.addGestureRecognizer(tapGesture)
view.addSubview(skView)
}
我可以访问它:
@IBAction func colorPickerOfColor(sender: UIButton) {
var pickerName = ""
switch sender.tag {
case 0:
pickerName = "green"
case 1:
pickerName = "red"
case 2:
pickerName = "blue"
default:
pickerName = "orange"
}
pickerName += "ColorPicker"
colorPickerView.image = UIImage(named: pickerName)
currentColorName = ColorSelection.fromRaw(sender.tag + 1)!.colorName
let color = ColorSelection.fromRaw(sender.tag + 1)!.getSKColor()
scene.lineColor = color
linesLeftCountLabel.textColor = color
}
这是编译器抱怨的地方:
func lineHasBeenDrawn() {
linesLeftCountLabel.text = "Any String"
}
答案 0 :(得分:0)
对不起那些家伙。 lineHasDrawn是一个委托方法,这就是为什么奇怪的行为。 我的坏。
答案 1 :(得分:0)
请检查您是否已将故事板中的引用插座连接到代码的IBOutlet