问题描述
我有带有键及其值的 NSDictionary,我希望它填充到 tableview 中,但是我得到了一些这样的错误:
i have NSDictionary with with key and its value and i want it to populate into the tableview but i get some error like this:
-[__NSArrayM isEqualToString:]: unrecognized selector sent to instance 0x8f8e4d0
2014-08-13 13:29:45.357 SotaApp[1602:60b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayM isEqualToString:]: unrecognized selector sent to instance 0x8f8e4d0'
我尝试过的是:
NSString *value = [filteredDictionaryValues valueForKey:[filteredDictionaryValues.allKeys objectAtIndex:indexPath.row]];
cell.textLabel.text =[filteredDictionaryValues.allKeys objectAtIndex:indexPath.row];
cell.detailTextLabel.text = value;
请告诉我是什么问题,谢谢.
Please tell me whats the problem,thank you.
编辑字典是这样的:
activity = (
"0Pharmacology.html"
);
acute = (
"0Pharmacology.html"
);
adenosine = (
"0Guidelines Precautions.html"
);
administration = (
"0Guidelines Precautions.html"
);
aneurysm = (
"0Dilution for Infusion.html"
);
arrhythmias = (
"0Guidelines Precautions.html"
);
artery = (
"0Dilution for Infusion.html"
);
asthma = (
"0Guidelines Precautions.html"
);
atrium = (
"0Dosing.html"
);
我已经从搜索方法中过滤了字典:
I have filtered the dictionary from search method:
-(void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText
{
if (searchText.length == 0) {
isSearching = NO;
}
else{
isSearching = YES;
}
NSPredicate *predicate =[NSPredicate predicateWithFormat:@"self beginswith[c] %@",searchText];
NSArray *filteredKeys =[[myDictionary allKeys]filteredArrayUsingPredicate:predicate];
NSLog(@"filtered keys are %@",filteredKeys);
filteredDictionaryValues =[myDictionary dictionaryWithValuesForKeys:filteredKeys];
NSLog(@"filteredDicValues are %@",filteredDictionaryValues);
[self.SerchTable reloadData];
}
推荐答案
当你调用 [filteredDictionaryValues valueForKey:[filteredDictionaryValues.allKeys objectAtIndex:indexPath.row]]
时,返回的值为 NSArray with 1字符串对象 (NSArray *array = [filteredDictionaryValues valueForKey:[filteredDictionaryValues.allKeys objectAtIndex:indexPath.row]]; NSString *string = [array firstObject];
).如果可以,您应该更改填充字典的方式(而不是只有 1 个对象的数组).如果没有,只需使用返回数组中的 firstObject.
When you are calling [filteredDictionaryValues valueForKey:[filteredDictionaryValues.allKeys objectAtIndex:indexPath.row]]
, value returned is NSArray with 1 string object (NSArray *array = [filteredDictionaryValues valueForKey:[filteredDictionaryValues.allKeys objectAtIndex:indexPath.row]]; NSString *string = [array firstObject];
). If you can, you should change the way dictionary is populated(instead of array with 1 object just object). If not, just use firstObject from returned array.
这篇关于_NSArrayM isEqualToString:]: 无法识别的选择器发送到实例 0x8d70f00的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!