为了避免重复,你怎么能转换这样的东西:
self.upperTextField.delegate = self
self.lowerTextField.delegate = self
进入:
func setDelegates(textField: UITextField){
textField.delegate = self
print("delegates set")
}
答案 0 :(得分:2)
您可以修改函数以接受UITextField
个对象数组:
func setDelegates(delegate: UITextFieldDelegate, textFields: [UITextField]) {
for textField in textFields {
textField.delegate = delegate
}
print("delegates set")
}
然后这样称呼:
setDelegates(self, textFields: [upperTextField, lowerTextField])