我想创建一个 UISearchBar 函数,它像 App Store 中的搜索一样被调用:在用户完成输入几秒钟后(NSTimer)执行函数(NSURLConnection),并且在此期间只执行一次。
有人有想法吗?
编辑
self.currentTaskID = self.currentTaskID + 1;
NSInteger taskID = self.currentTaskID;
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1 * NSEC_PER_SEC), queue, ^{
if (taskID == self.currentTaskID)
{
NSMutableURLRequest *request_CH3 = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://website.com/search.php?term=%@", replaceWhiteSpace]]
cachePolicy:NSURLRequestReloadIgnoringLocalCacheData
timeoutInterval:30.0];
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
authConnection_CH3 = [[NSURLConnection alloc] initWithRequest:request_CH3 delegate:self];
}
});