1
//时间间隔
NSTimeInterval textFieldDidChangeInterval;
//定时器
NSTimer *_timer;
- (void)textTimer_search:(UITextField*)textField{
NSTimeInterval start =CACurrentMediaTime();
if (start -textFieldDidChangeInterval <1.0) {
textFieldDidChangeInterval = start;
[_timer invalidate];
_timer = nil;
_timer = [NSTimer scheduledTimerWithTimeInterval:1.0 repeats:NO block:^(NSTimer * _Nonnull timer) {
[self req_searchList:textField.text];
}];
[[NSRunLoop currentRunLoop] addTimer:_timer forMode:NSDefaultRunLoopMode];
}else{
textFieldDidChangeInterval = start;
//发起请求获取数据
[self req_searchList:textField.text];
}
}