【发布时间】:2016-05-14 16:26:11
【问题描述】:
我想在所有 uitextfield 上使用 resign 第一响应者。我可以通过将uitextfields 放在一个数组中来完成此操作,但我想避免使用该数组。辞职应该发生在所有类型的 uiTextField 上怎么办。
这很好用
class ViewController: UIViewController, UITextFieldDelegate {
@IBOutlet weak var text: UITextField!
@IBOutlet weak var textFieldtwo: UITextField!
var textField = [UITextField]()
override func viewDidLoad() {
super.viewDidLoad()
self.textField = [text,textFieldtwo]
for item in textField {
item.delegate = self
}
}
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
print("text")
for item in textField {
item.resignFirstResponder()
}
}
}
【问题讨论】: