我正在使用以下代码遍历 plist 以找到一个字符串,然后我想使用键的值 - 不幸的是,分数和数字有些东西不起作用,我无法弄清楚
任何帮助将不胜感激
NSString *theNumber = @"0.0075";
BOOL found = NO;
NSUInteger f;
for (f = 0; f < [selectorKeysFractions count]; f++) {
NSString * stringFromArray = [selectorKeysFractions objectAtIndex:f];
if ([theNumber isEqualToString:stringFromArray]) {
found = YES;
break;
}
}
if ( found ) {
// do found
//this line fails with unrecognised selector message
NSLog(@"%@",[[selectorKeysFractions objectAtIndex:f]objectForKey:@"fraction"]);
} else {
// do not found
}
我的 plist 数据看起来像这样
<plist version="1.0">
<dict>
<key>fraction</key>
<string>1/128</string>
<key>number</key>
<string>23.78</string>
</dict>
<dict>
<key>fraction</key>
<string>1/234</string>
<key>number</key>
<string>25</string>
</dict>
</plist>
我正在像这样设置数组
NSString *path2 = [[NSBundle mainBundle] pathForResource:@"Fractions" ofType:@"plist"];
pickerData2 =[[NSDictionary alloc]initWithContentsOfFile:path2];
selectorKeysFractions = [[NSArray alloc] initWithArray:[pickerData2 allKeys]];
我做错了什么,但无法弄清楚请帮忙
谢谢