@interface XXX
@property (nonatomic, assign) NSInteger inputCount; //用户输入次数,用来控制延迟搜索请求
@end
- (void)inputBarTextViewDidChange:(HPGrowingTextView *)textView hasInputText:(NSString *)text {
// 用户停止输入1秒后进行提示内容匹配搜索
self.inputCount ++;
[self performSelector:@selector(requestKeyWorld:) withObject:@(self.inputCount) afterDelay:1.0f];
}
- (void)requestKeyWorld:(NSNumber *)count {
if (self.inputCount == [count integerValue]) {
//说明用户停止输入超过了一秒,发起网络请求
[self.searchOperation cancel];
//执行网络请求
self.searchOperation = [HTTP XXX];
}
}
网友评论