swift:UITextField没有名为text的成员

时间:2014-06-24 17:42:03

标签: ios uitextfield swift

我在事件编辑开始时有@IBAction

@IBAction func saveCurrentTextField(sender: UITextField) {

    let myTextField : UITextField = sender as UITextField
    myClass.saveMyTextField(myTextField)

}

然后我在事件Touch Up Inside上有@IBAction按钮

@IBAction func saveValueOfThoseTextField(sender: UIButton) {

    println("Those textField = \(myClass.thoseTextField)")
    let text : String = myClass.thoseTextField.text

}

println return:

UITextField: 0xb289b80; frame = (165 15; 40 30); text = '15'; clipsToBounds = YES; opaque = NO; autoresize = RM+BM; gestureRecognizers = NSArray: 0xb28f730>; layer = CALayer: 0xb289cc0

但在字符串let text : String = myClass.thoseTextField.text上,我收到错误:UITextField does not have a member named text

2 个答案:

答案 0 :(得分:4)

尝试:

let text : String = myClass.thoseTextField!.text

您引用的文本字段可能是IBOutlet,并且是可选的。

答案 1 :(得分:1)

@IBOutlet var txt_RegNumber:[UITextField]!

你可能有这样的只是删除[] 因为将数组作为默认值