标签: s7graphview

通过字典循环; 为什么我不按字母顺序获取键?

我正在使用S7Graphview编写一个iPhone应用程序,我将一些日期和结果保存为.plist作为字典中的键和值,两者都作为字符串.我的plist看起来像这样:

<dict>
<key>2011-05-11</key>
<string>23</string>
<key>2011-05-12</key>
<string>23</string>
<key>2011-05-13</key>
<string>23</string>
<key>2011-05-14</key>
<string>43</string>
<key>2011-06-14</key>
<string>43</string>
</dict>
Run Code Online (Sandbox Code Playgroud)

然后我使用这个循环将这些值加载到graphview中:

NSMutableDictionary* dictionary = [[NSMutableDictionary alloc]init];
if ([[NSFileManager defaultManager] fileExistsAtPath:filePath]) 
    dictionary = [NSMutableDictionary dictionaryWithContentsOfFile:filePath];
int i = 1;        

if ([dictionary count] > 0) {
for (NSString* key in dictionary){
    NSString* verdiString = [dictionary objectForKey:key];
    CGFloat verdi = [verdiString intValue];
    NSDate *dato = [[NSDate alloc]init];
    NSLog(@"key=%@ value=%@", key, [dictionary objectForKey:key]);
    dato = [self stringTilDato:key];
    [items.list_ addObject:[[GraphInfo alloc] initWithID:i name:verdiString value:verdi date:dato]];
    i++;
}
}
Run Code Online (Sandbox Code Playgroud)

"stringTilDato"方法将日期字符串转换为NSDate.值被加载到items.list中,但顺序错误!NSLog报告:

key=2011-05-14 value=43
key=2011-05-13 …
Run Code Online (Sandbox Code Playgroud)

iphone objective-c nsmutabledictionary s7graphview

2
推荐指数
1
解决办法
396
查看次数