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

发布于 2022-09-02 11:40:35 字数 1911 浏览 12 评论 0

有没有做过"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;
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

嘿看小鸭子会跑 2022-09-09 11:40:35

回调方法里面 你的tableViewreloadData啊.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文