我有一个包含乌尔都语单词和英语单词的 plist。如下图所示
现在我的代码是获取数据如下
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[words removeAllObjects];
[means removeAllObjects];
NSString *path = [[NSBundle mainBundle] pathForResource:
@"urdutoeng" ofType:@"plist"];
NSMutableArray *array2 = [[NSMutableArray alloc] initWithContentsOfFile:path];
for (int i=0; i<[array2 count]; i++) {
NSDictionary* dict = [array2 objectAtIndex:i];
[words addObject:[dict valueForKey:@"Urdu"]];
[means addObject:[dict valueForKey:@"English"]];
[Types addObject:[dict valueForKey:@"Nature"]];
}
}
这部分代码对我来说很好,就像我下面的屏幕截图一样
现在的问题是,当我通过搜索栏搜索任何单词时,它返回空结果,因为我的搜索数组包含不同格式的单词,我的搜索数组代码是
listOfItems = [[NSMutableArray alloc] init];
NSDictionary *countriesToLiveInDict = [NSDictionary dictionaryWithObject:words forKey:@"Countries"];
[listOfItems addObject:countriesToLiveInDict];
copyListOfItems = [[NSMutableArray alloc] init];
我的搜索栏代码是
#pragma mark Content Filtering
- (void)filterContentForSearchText:(NSString*)searchText
{
[copyListOfItems removeAllObjects];
NSLog(@"listOfItemsdata :%@",listOfItems);
for (NSString *cellLabel in [[listOfItems objectAtIndex:0] objectForKey:@"Countries"])
{
NSComparisonResult result = [cellLabel compare:searchText options: (NSCaseInsensitiveSearch|NSDiacriticInsensitiveSearch) range:NSMakeRange(0, [searchText length])];
if (result == NSOrderedSame)
{
[copyListOfItems addObject:cellLabel];
}
}
}
#pragma mark UISearchDisplayController Delegate Methods
- (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString
{
NSLog(@"searchstring :%@",searchString);
[self filterContentForSearchText:searchString];
return YES;
}
当我对 listOfItems 数组进行 Nslog 记录时,它会显示一些类似的文本
NSLog(@"listOfItemsdata :%@",listOfItems);
listOfItemsdata:({国家=(“\U0627\U0628”,“\U0627\U0628\U0628\U06be\U06cc”,“\U0627\U0628\U062a\U0628”,“\U0627\U0628\U062a\U06a9”,“ \U0627\U0628 \U062c\U0628 \U06a9\U06c1", " \U0627\U0628 \U0633\U06d2",它表明我的数据以其他格式出现,这就是为什么搜索栏无法搜索它。任何帮助或建议将是得到了。谢谢