我的搜索栏中有两个范围:城市和教堂。每次我执行搜索时,两个范围都会显示空白单元格,而它们确实有搜索结果。如何显示它们对应的单元格名称?谢谢!
我认为问题出在我的 cellForRowAtIndexPath
if (tableView == self.searchDisplayController.searchResultsTableView) {
if ([searchBar.scopeButtonTitles isEqual: @"City"]) {
cell.textLabel.text = [[filteredResult objectAtIndex: indexPath.row] objectForKey: @"Places"];
}
else if ([searchBar.scopeButtonTitles isEqual: @"Church"]) {
cell.textLabel.text = [[filteredResult objectAtIndex: indexPath.row] objectForKey: @"Church"];
}
}
else {
...
}
[cell setAccessoryType: UITableViewCellAccessoryDisclosureIndicator];
return cell;
这是我的搜索:
- (void)filterListForSearchText:(NSString *)searchText scope:(NSString *)scope
{
[filteredResult removeAllObjects];
if ([scope isEqualToString: @"City"]) {
for (NSDictionary *dictionarySearch in allRegion) {
for (NSDictionary *citySearch in [dictionarySearch objectForKey: @"Cities"]) {
[citySearch objectForKey: @"Cities"];
NSRange rangeSearch = [[citySearch valueForKey: @"Places"] rangeOfString: searchText options: (NSCaseInsensitiveSearch|NSDiacriticInsensitiveSearch)];
if (rangeSearch.location != NSNotFound) {
[filteredResult addObject: citySearch];
}
}
}
}
if ([scope isEqualToString: @"Church"]) {
for (NSDictionary *dictionarySearch in allRegion) {
for (NSDictionary *citySearch in [dictionarySearch objectForKey: @"Cities"]) {
for (NSDictionary *churchSearch in [citySearch objectForKey: @"Churches"]) {
[churchSearch objectForKey: @"Churches"];
NSRange rangeSearch = [[churchSearch valueForKey: @"Church"] rangeOfString: searchText options: (NSCaseInsensitiveSearch|NSDiacriticInsensitiveSearch)];
if (rangeSearch.location != NSNotFound) {
[filteredResult addObject: churchSearch];
}
}
}
}
}
}