Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

}

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
167 views
Welcome To Ask or Share your Answers For Others

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...