這個是對UITextField的文本進行動態監控,進行動態設置控件狀態的方法。
1.添加當前ViewController爲觀察者,來監聽名稱爲UITextFieldTextDidChangeNotification的通知
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(textFieldTextDidChange:) name:UITextFieldTextDidChangeNotification object:nil];
2.這裏就可以針對這個通知進行相關處理
if ([[notification name] isEqualToString:UITextFieldTextDidChangeNotification]) {
if ([[codeTextField text] length]) {
registerButton.enabled = YES;
registerButton.backgroundColor = [UIColor colorWithHexString:@"#00c0cc"];
}else
{
registerButton.enabled = NO;
registerButton.backgroundColor = [UIColor grayColor];
}
}