tags:

views:

32

answers:

1

Hello everyone,

I have one query regarding the (UITextfield and Webservice) for example

When i start writing text in UITextfield. Make sure, the app does not query the server(Webservice) for each letter typed. It should wait till I make a pause and then send the request.

Is this possible to when using of UITextField?

Thanks in advance

+1  A: 

You can do that using performSelector:withObject:afterDelay: and cancelPreviousPerformRequestsWithTarget: methods. Here's sample code - requestAction: gets called after user makes 2sec pause in editing text field.

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
    // Cancel previously registered perform request 
    [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(requestAction) object:nil];
    // schedule a call with 2 sec delay
    [self performSelector:@selector(requestAction) withObject:nil afterDelay:2.0];

    return YES;
}

- (void) requestAction{
    NSLog(@"Request!");
}
Vladimir
Thanks you so much Vladimir, it working for me. my problem is solved.Thank a lots.
milanjansari