我有需要为其编写搜索机制的 UIPicker。提供给这个选择器的数据是一个字符串数组。当用户输入搜索字符串时(我有一个 UISearchBar 来处理它。)我想找到包含搜索词的所有字符串。从下面的示例中,似乎我需要编写一个谓词然后过滤数组。我现在遇到的问题是我不知道如何向用户显示搜索结果。我尝试将结果集分配回原始数组,但这是不正确的。有人可以建议一种通过代码示例实现 UIPicker 搜索的技术吗?
NSMutableArray* names = [NSMutableArray arrayWithObjects:@"Andy", @"Bart", @"Bob", nil];
NSPredicate* predicate = [NSPredicate predicateWithFormat:@"SELF beginswith[c] 'b'"];
NSArray* namesStartingWithB = [names filteredArrayUsingPredicate: predicate];