在这里使用addTarget比较好
- (void)viewDidLoad {
[super viewDidLoad];
[self.nameField addTarget:self action:@selector(textValueChanged) forControlEvents:UIControlEventEditingChanged];
[self.phoneField addTarget:self action:@selector(textValueChanged) forControlEvents:UIControlEventEditingChanged];
}
/**
* 监听文本输入框内容的改变
*/
- (void)textValueChanged{
self.addBtn.enabled = (self.nameField.text.length != 0 && self.phoneField.text.length != 0);
}
UIControlEventEditingChanged是重点,不要写成了UIControlEventValueChanged