How about this if you detect text input in the UITextFieldDelegate method:
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string { [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(sendNetworkRequest) object:nil]; [self performSelector:@selector(sendNetworkRequest) withObject:nil afterDelay:0.5]; return YES; } - (void)sendNetworkRequest {
I like this rating for such problems, as it means I donβt need to use NSTimer or track any state, whether I expect to see more text entered or not. Hope this helps! Let me know if you have any questions.
EDIT:. You see that you are using the search bar instead. The principle is the same, just put the pairing / pairing in the corresponding UISearchBarDelegate method.
source share