嗨我在函数示例中有for循环的UITextFields:
func textfieldsinfunc(){
for....{
//5 times for example
var textField:UITextField = UITextField(frame: CGRectMake(addedNX, fieldHeight, 143, 30))
textField.borderStyle = .RoundedRect
self.scrollView.addSubview(textField)
}
}
如何在函数外部获取这5个textField的文本?
答案 0 :(得分:2)
您可以使用标记来识别UIView。
for index in 1...5 {
//5 times for example
var textField:UITextField = UITextField(frame: CGRectMake(10, 100, 143, 30))
textField.borderStyle = .RoundedRect
textField.tag = index
self.scrollView.addSubview(textField)
}
并在函数
之外使用viewWithTaglet textField: UITextField = scrollView.viewWithTag(1) as UITextField