_NSArrayM isEqualToString:]: unrecognized selector sent to instance 0x8d70f00

六眼飞鱼酱① 提交于 2019-12-12 06:48:37

问题


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'  

what i have tried is:

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.

EDIT the dictionary looks like this:

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];

}


回答1:


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.



来源:https://stackoverflow.com/questions/25281629/nsarraym-isequaltostring-unrecognized-selector-sent-to-instance-0x8d70f00

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!