UITextField - 无法解包Optional.None

时间:2014-07-03 19:41:27

标签: ios uitextfield swift

我刚开始使用Swift进行编码,我尝试构建一个计算器。当我启动模拟器时,我点击按钮' 1'它称为Tap0功能的计算器。我遇到了以下问题:Can't unwrap Optional.None.

import UIKit

class ViewController: UIViewController {
  @IBOutlet var display:UITextField

  override func viewDidLoad() {
    super.viewDidLoad()
  }

  override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
  }

  @IBAction func Tap0(sender:AnyObject){AddNumber("0")}

  func AddNumber(x:String){
    self.display.text="" //ERROR (Can't unwrap Optional.None)
    println(self.display.text)
  }
}

我如何解决?

1 个答案:

答案 0 :(得分:1)

正如rdelmar建议的那样,要解决错误,请将显示连接到StoryBoard中的UITextField:

enter image description here