1
我在想,如果你可以做這樣的事情:通字典給選擇
[self.verificationCodeField addTarget:self
action:@selector(textFieldDidChange:)
forControlEvents:UIControlEventEditingChanged];
[self.verificationCodeField1 addTarget:self
action:@selector(textFieldDidChange:)
forControlEvents:UIControlEventEditingChanged];
[self.verificationCodeField2 addTarget:self
action:@selector(textFieldDidChange:)
forControlEvents:UIControlEventEditingChanged];
[self.verificationCodeField3 addTarget:self
action:@selector(textFieldDidChange:)
forControlEvents:UIControlEventEditingChanged];
[self.verificationCodeField4 addTarget:self
action:@selector(textFieldDidChange:)
forControlEvents:UIControlEventEditingChanged];
以更有效的方式。我嘗試將它們分組爲可變綁定,如下所示:
NSDictionary *dictWithAllTheTextFields =
NSDictionaryOfVariableBindings(self.verificationCodeField,
self.verificationCodeField1,self.
verificationCodeField2,
self.verificationCodeField3,
self.verificationCodeField4);
然後將整個組傳遞給選擇器,但那也不起作用。
也沒有這項工作:
for(UITextField *textField in dictWithAllTheTextFields){
[textField addTarget:self action:@selector(textFieldDidChange:)
forControlEvents:UIControlEventEditingChanged];
}
,這是什麼情況下最有效的方法是什麼?