例如,需要監(jiān)聽手機(jī)號碼TextField中輸入字?jǐn)?shù)到11位時候才讓“獲取短驗Button”可點擊。
方法如下:
在ViewDidLoad中添加以下方法:
[NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(checkTextFieldInput) userInfo:nil repeats:YES];
scheduledTimerWithTimeInterval為監(jiān)聽時間間隔,這里設(shè)0.1秒。
selector:@selector(checkTextFieldInput)這里需要在下面寫一個方法命名為checkTextFieldInput,里面就可以編寫相應(yīng)邏輯了:
- (void)checkTextFieldInput{
if(textField.text.length == 11){
self.xxxButton.userInteractionEnabled = YES ;
}
}