gpt4 book ai didi

ios - iPad 搜索显示 Controller 从第二个单元格开始显示结果

转载 作者:行者123 更新时间:2023-11-28 22:17:50 25 4
gpt4 key购买 nike

我在使用 localSearch 的 iPad 应用程序中添加了搜索栏和搜索显示 Controller 。我相信我正确地实现了代表。搜索工作正常并显示结果,但问题是这些结果从第二个单元格开始。弹出显示中的第一个单元格为空。我仔细检查了 map 项目计数和内容是否正确,它们是正确的。

代码:

- (void) searchBarSearchButtonClicked:(UISearchBar *)searchBar
{
if (![self connected]) {
[[[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Cannot Connect",nil)
message:NSLocalizedString(@"Please make sure you are connected to the internet and try again.",nil)
delegate:nil
cancelButtonTitle:NSLocalizedString(@"OK",nil) otherButtonTitles:nil] show];
}
else if ([mainToolbar isHidden])
{
[[[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Search Unavailable",nil)
message:NSLocalizedString(@"Please make sure you aren't drawing an AOI or using a tool and then try again.",nil)
delegate:nil
cancelButtonTitle:NSLocalizedString(@"OK",nil) otherButtonTitles:nil] show];
}
else {
// Cancel any previous searches.
[localSearch cancel];

// Perform a new search.
MKLocalSearchRequest *request = [[MKLocalSearchRequest alloc] init];
request.naturalLanguageQuery = self.searchBar.text;
request.region = self.mapView.region;

[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
localSearch = [[MKLocalSearch alloc] initWithRequest:request];

[localSearch startWithCompletionHandler: ^(MKLocalSearchResponse *response, NSError *error){
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;

if ([response.mapItems count] == 0)
{
[[[UIAlertView alloc] initWithTitle:NSLocalizedString(@"No Results",nil)
message:nil
delegate:nil
cancelButtonTitle:NSLocalizedString(@"OK",nil) otherButtonTitles:nil] show];
return;
}

if (error != nil)
{
[[[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Map Error",nil)
message:NSLocalizedString(@"Sorry.", nil)
delegate:nil
cancelButtonTitle:NSLocalizedString(@"OK",nil) otherButtonTitles:nil] show];
return;
}

results = response;

[self.searchDisplayController.searchResultsTableView reloadData];
}


];
}
}


- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [results.mapItems count];
}


- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *IDENTIFIER = @"SearchResultsCell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:IDENTIFIER];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:IDENTIFIER];
}

MKMapItem *item = results.mapItems[indexPath.row];

cell.textLabel.text = item.name;
cell.detailTextLabel.text = item.placemark.addressDictionary[@"Street"];

return cell;
}

这是问题的屏幕截图。

Search display skipping the first cell

最佳答案

第一行包含表头。

关于ios - iPad 搜索显示 Controller 从第二个单元格开始显示结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21173371/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com