Yes, we can check it out! with delegate UITextField , - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
- (void) callMeAfterTwoSeconds { NSLog(@"I'll call after two seconds of inactivity!"); } - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string { [NSRunLoop cancelPreviousPerformRequestsWithTarget:self]; [self performSelector:@selector(callMeAfterTwoSeconds) withObject:nil afterDelay:2.0]; return YES; }
While you are typing (by pressing the keys on the keyboard), it cancels previous calls to the callMeAfterTwoSeconds function, after you stop, it makes it ring after 2 seconds of delay, and yes, it will ring after 2 seconds.
Update: Even you can pass this text field as an object to performSelector to find out which text field is inactive, what your callMeAfterTwoSeconds function will be callMeAfterTwoSeconds ,
- (void) callMeAfterTwoSeconds:(UITextField *)textfield { if(textfield == txtUserName) { NSLog(@"User textfield has NO activity from last two seconds!"); } }
source share