例:
<dict>
<key>Feb 7, 2000</key>
<array>
<string>7</string>
<string>8</string>
</array>
<key>Jan 27, 2001</key>
<array>
<string>8</string>
<string>7</string>
</array>
</dict>
法典:
NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithContentsOfFile:path];
for(id key in dict) {
NSLog(@"First:%@ Second:%@", [[dict objectForKey:key] objectAtIndex:0], [[dict objectForKey:key] objectAtIndex:1]);
}
产出:
First:7 Second:8
First:8 Second:7
EDIT (response to comment)
First you need to determine the keys within the NSMutableDictionary
.
Load the .plist
file, loop through and add the keys to an NSMutableArray
.
NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithContentsOfFile:path];
NSMutableArray *keys = [[NSMutableArray alloc] init];
for(id key in dict) [keys addObject:[NSString stringWithFormat:@"%@",key]];
Make sure the array can be accessed by the UIPickerView
.
The UIPickerView
should be able to retrieve the keys like this:
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component;
{
return [keys objectAtIndex:row];
}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component;
{
return [keys count];
}
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView;
{
return 1;
}
最后,更新<条码>IDLabel>。
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
theLabel.text = [NSString stringWithFormat:@"First:%@ Second:%@",
[[dict objectForKey:[keys objectAtIndex:row]] objectAtIndex:0],
[[dict objectForKey:[keys objectAtIndex:row]] objectAtIndex:1]];
}
http://www.un.org/Depts/DGACM/index_french.htm 现有几行:
Feb 7, 2000
Jan 27, 2001
如选定“Jan 27,2001年”,UILabel
:
First:8 Second:7