首页 > iOS:有没有做过"UISearchBar+百度地图在线建议查询"搜索地名的功能的?

iOS:有没有做过"UISearchBar+百度地图在线建议查询"搜索地名的功能的?

有没有做过"UISearchBar+百度地图在线建议查询"搜索地名的功能的?
我用 UISearchBar + 百度地图在线建议查询 第一次搜索无结果, 以后搜索的都是上一次的结果, 求大神指点该怎么做?

部分代码如下:

- (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString {
   
    // 发送内容进行搜索
    BMKSuggestionSearchOption* option = [[BMKSuggestionSearchOption alloc] init];
    option.keyword  = searchString;
    [self.searcher suggestionSearch:option];
   
   
    //刷新表格
    return YES;
}


//实现Delegate处理回调结果
- (void)onGetSuggestionResult:(BMKSuggestionSearch*)searcher result:(BMKSuggestionResult*)result errorCode:(BMKSearchErrorCode)error{
    if (error == BMK_SEARCH_NO_ERROR) {
        
        self.keyListArray = result.keyList;
        self.cityListArray = result.cityList;
        self.districtListArray = result.districtList;
        
    }
    else {
        NSLog(@"抱歉,未找到结果");
    }
}




#pragma mark - UITableview相关
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (tableView == self.searchDisplayController.searchResultsTableView) {
        
        return [self.keyListArray count];
        
    }else{
        return 0;
    }
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *flag=@"cellFlag";
    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:flag];
    if (cell==nil) {
        cell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:flag];
    }
   
    if (tableView==self.searchDisplayController.searchResultsTableView) {
        [cell.textLabel setText:self.keyListArray[indexPath.row]];
    }
    //    else{
    //        [cell.textLabel setText:self.dataList[indexPath.row]];
    //    }
    return cell;
}

回调方法里面 你的tableViewreloadData啊.

【热门文章】
【热门文章】