UITableView中带.plist的UISearchBar

UITableView中带.plist的UISearchBar,uitableview,plist,uisearchbar,Uitableview,Plist,Uisearchbar,在过去,我遵循一个小教程在我的UITableView中实现了一个UISearchBar 它是由数组组成的。现在我有了处理所有事情的.plist文件,搜索栏会是什么样子? 我是说,我做了一些类似的事情: copyLists = [[NSMutableArray alloc] initWithArray:sortedList copyItems:YES]; 其中sortedList是包含plist的数组 基本上,搜索栏工作正常,但当我输入一个单词时,它不会显示任何单元格,即使我输入了单元格的确切

在过去,我遵循一个小教程在我的UITableView中实现了一个UISearchBar

它是由数组组成的。现在我有了处理所有事情的.plist文件,搜索栏会是什么样子? 我是说,我做了一些类似的事情:

 copyLists = [[NSMutableArray alloc] initWithArray:sortedList copyItems:YES];
其中sortedList是包含plist的数组

基本上,搜索栏工作正常,但当我输入一个单词时,它不会显示任何单元格,即使我输入了单元格的确切名称

它是否应该返回plist中包含的键
name
,该键是单元格的名称

搜索栏将如何使用plists进行更改

- (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString
{
    [self.filteredList removeAllObjects]; // First clear the filtered array.

    NSArray *objcts = unfilteredList;

    for (NSDictionary *section in objcts)
    {
        for (NSDictionary *row in [section valueForKey:@"Rows"])
        {
            NSRange rng = [[row valueForKey:@"name"] rangeOfString:searchString options:(NSCaseInsensitiveSearch|NSDiacriticInsensitiveSearch)];

            if (rng.length != 0)
                [self.filteredList addObject:row];
        }
    }
    // Return YES to cause the search result table view to be reloaded.
    return YES;
}
确保您的
搜索栏和搜索显示控制器
代理
设置正确。然后,用于显示单元格用途:

NSArray *rows;
if (tableView == self.searchDisplayController.searchResultsTableView)
{
    rows = filteredList;
} else {
    NSDictionary *section = [unfilteredList objectAtIndex:indexPath.section];
    rows = [section objectForKey:@"Rows"];
}
cell.textLabel.text = [[rows objectAtIndex:indexPath.row] objectForKey:@"name"];

并更改
行数
标题标题
等的逻辑。

我可以问一下
@“行”
与此有什么关系吗?我对我的搜索功能有些迷茫:|数组是一个节数组,每个节都有自己的行。我正在使用
objectForKey:@“Rows”
访问此子字典,为什么我无法访问我的子目录。我的主目录是Places,子目录是Church。如果我使用你的代码,我就可以获得豁免|我想你的字典的名字很像这个地方。因此,您必须使用地名作为键
objectForKey:@“PlaceName”
。在此示例中,有一个具有多个键和值的dic。其中一个称为“行”,它包含一个包含行的数组。