在这行代码上:
if diceRoll == userGuessTextField.text {
我收到此错误:
2016-02-04 18:38:34.756 How Many Fingers[2972:158461] Can't find keyplane that supports type 4 for keyboard iPhone-PortraitChoco-NumberPad; using 1336863583_PortraitChoco_iPhone-Simple-Pad_Default
fatal error: unexpectedly found nil while unwrapping an Optional value
(lldb)
这是我的代码:
import UIKit
class ViewController: UIViewController {
@IBOutlet var userGuessTextField: UITextField!
@IBOutlet var resultLabel: UILabel!
@IBAction func guess(sender: AnyObject) {
let diceRoll = String(arc4random_uniform(6))
if diceRoll == userGuessTextField.text {
resultLabel.text = "You're right!"
}
else {
resultLabel.text = "Wrong! It was a " + diceRoll
}
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
答案 0 :(得分:0)
这只是一个警告,键盘类型不存在,很可能已弃用。
2016-02-04 18:38:34.756 How Many Fingers[2972:158461] Can't find keyplane that supports type 4 for keyboard iPhone-PortraitChoco-NumberPad; using 1336863583_PortraitChoco_iPhone-Simple-Pad_Default
另一方面,这是一个错误,很可能是因为userGuessTextField.text
是nil
并且无法进行比较。
fatal error: unexpectedly found nil while unwrapping an Optional value (lldb)
此处的解决方案是检查userGuessTextField.text
是否有值,并建议 beyowulf ,您应该将userGuessTextField
连接到其storyboard元素。