OC中监听输入框的方法

例如,需要监听手机号码TextField中输入字数到11位时候才让“获取短验Button”可点击。
方法如下:
ViewDidLoad中添加以下方法:

[NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(checkTextFieldInput) userInfo:nil repeats:YES];

scheduledTimerWithTimeInterval为监听时间间隔,这里设0.1秒。
selector:@selector(checkTextFieldInput)这里需要在下面写一个方法命名为checkTextFieldInput,里面就可以编写相应逻辑了:

- (void)checkTextFieldInput{
    if(textField.text.length == 11){
        self.xxxButton.userInteractionEnabled = YES ;
    }
}
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容