検索バーには、CityとChurchの2つのスコープがあります。検索を実行するたびに、両方のスコープに空白のセルが表示されますが、検索結果は表示されます。対応するセル名を表示するにはどうすればよいですか?ありがとうございました!
私は問題が私の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];
}
}
}
}
}
}