我有以下过滤某些结果的方法:目前它这样做:array: alpha, apple, aries, bravo
输入一个:
阿尔法苹果白羊座
l 型(现在是 al)
α
我想这样做:
新搜索:输入 p= alpha apple
下面是代码
提前谢谢你
-(void) filterResults:(NSString *)searchText{
NSMutableArray *test = [NSMutableArray arrayWithArray:self.listContent];
[self.filteredListContent removeAllObjects]; // First clear the filtered array.
for (int i=0; i<[test count]; i++) {
NSString *stringResult = [test objectAtIndex:i];
NSComparisonResult result = [stringResult compare:searchText options:(NSCaseInsensitiveSearch|NSDiacriticInsensitiveSearch) range:NSMakeRange(0, [searchText length])];
if (result == NSOrderedSame){
[self.filteredListContent addObject:stringResult];
}
}
[self.filteredListContent sortUsingSelector:@selector(localizedCaseInsensitiveCompare:)];//sort alphabetically
NSLog(@"filtered results = %@",self.filteredListContent);
}