iOS 取消上一次的调用,给定时间内对同一方法只调用一次

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
    [NSObject cancelPreviousPerformRequestsWithTarget:self];
    NSString *testObj =[textField.text stringByReplacingCharactersInRange:range withString:string];
    [self performSelector:@selector(goSearch:) withObject:subString afterDelay:.25f];
    return YES;
}

- (void)goSearch:(NSString *)searchString{
    NSLog(@"come on!,%@", searchString);
}

你可能感兴趣的:(iOS 取消上一次的调用,给定时间内对同一方法只调用一次)