私は並べ替えた辞書を持っています。私の問題は、それをループすると再びソートされなくなることです。
//sort the poiIDArray so it appears alphabetically
NSArray *sortedValues = [[self.pois allValues] sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)];
NSMutableDictionary *orderedDictionary=[[NSMutableDictionary alloc]init];
for(NSString *valor in sortedValues){
for(NSString *clave in [self.pois allKeys]){
if ([valor isEqualToString:[self.pois valueForKey:clave]]) {
[orderedDictionary setValue:valor forKey:clave];
}
}
}
NSLog(@"ordered dic: %@",orderedDictionary);
//loop through dic and get names.
for(NSString *key in orderedDictionary) {
NSLog(@"%@",key);
}
これが私のログです。
2012-10-26 11:49:35.221 CPOP Test 4[1277:c07] ordered dic: {
"Badger Burgers" = 5;
"Costa Coffee" = 4;
"Spiffing Drinks" = 6;
"Vals Vegetables" = 7;
}
2012-10-26 11:49:35.221 CPOP Test 4[1277:c07] Costa Coffee
2012-10-26 11:49:35.222 CPOP Test 4[1277:c07] Spiffing Drinks
2012-10-26 11:49:35.222 CPOP Test 4[1277:c07] Badger Burgers
2012-10-26 11:49:35.222 CPOP Test 4[1277:c07] Vals Vegetables
なぜこれが起こっているのか、それを修正する方法を教えてもらえますか?