[英]Is there any way to perform delegation through a function?
為了避免重復,您如何轉換這樣的內容:
self.upperTextField.delegate = self
self.lowerTextField.delegate = self
進入:
func setDelegates(textField: UITextField){
textField.delegate = self
print("delegates set")
}
您可以修改函數以接受UITextField
對象的數組:
func setDelegates(delegate: UITextFieldDelegate, textFields: [UITextField]) {
for textField in textFields {
textField.delegate = delegate
}
print("delegates set")
}
然后這樣稱呼它:
setDelegates(self, textFields: [upperTextField, lowerTextField])
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.