我使用UIViewController,UISearchBarDelegate,UISearchDisplayDelegate实现了SearchBar,当搜索执行时,我的程序向服务器发送http请求,然后解析响应正文。这会导致搜索栏在每个字符输入后延迟几秒钟。
因此,我想关闭搜索栏的“实时搜索”,以便每次输入字符时都不会执行搜索。此外,当我单击键盘的“搜索”按钮时,我还想执行搜索并将数据显示到tableview。我该怎么办?
答案 0 :(得分:1)
致电[self.searchDisplayController.searchResultsTableView reloadData];
仅当您的搜索请求已完成时,仅在调用代理- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
时才发出搜索请求。
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
{
DLog(@"search text is %@",searchBar.text);
[self makeSearchRequest:searchBar.text];
}
-(void)makeSearchRequest:(NSString*)pString
{
CLLocation *location = [[AppHelper appDelegate] mLatestLocation];
NSMutableDictionary *paramDic = [[NSMutableDictionary alloc] init];
[paramDic setValue:[[AppHelper mDataManager] objectForKey:_KEY(KEY_USERID)] forKey:@"userid"];
[paramDic setValue:@"H0001" forKey:@"client"];
[paramDic setValue:[[AppHelper mDataManager] objectForKey:_KEY(KEY_LOCATION_ID)] forKey:@"locationid"];
[paramDic setValue:@"0" forKey:@"pageid"];
[paramDic setValue:@"10" forKey:@"displayrecords"];
// [paramDic setValue:[[dic objectForKey:@"birthday"] stringByReplacingOccurrencesOfString:@"/" withString:@"-"] forKey:@"dateofbirth"];
**[paramDic setValue:pString forKey:@"keyword"];**
[self.mWNetowrk makeRequsetWithURL:URL_SEARCH type:ReqSearch paramDictionary:paramDic delegate:self];
[paramDic autorelease];
}
-(void)network:(WNetwork*)network didFinishLoadingWithRequest:(NSInteger)pReq data:(NSMutableDictionary*)pData
{
[self removeLoader ];
switch (pReq) {
case ReqSearch:
self.mArrayPlaces = [pData objectForKey:@"places"];
[mPlacesCacheArray release];
mPlacesCacheArray=nil;
if (!mPlacesCacheArray) {
mPlacesCacheArray =[NSMutableArray new];
for (int i =0 ; i<[mArrayPlaces count]; i++) {
[mPlacesCacheArray addObject:[NSNull null]];
}
}
[self.searchDisplayController.searchResultsTableView reloadData];
break;
default:
break;
}
}