我正在从 plist 加载数据,并试图了解如何访问每个项目的数据。在下面的代码中,我希望能够提取文本的值以及它是 checked = 0 还是 checked = 1
我试过这个:
NSString *dataArray1 = [[dataArray objectAtIndex:1] objectAtIndex:2];
但想知道这是否是最好的方法
感谢您的帮助。
// load data from a plist file inside our app bundle
NSString *path = [[NSBundle mainBundle] pathForResource:@"Providers" ofType:@"plist"];
dataArray = [NSMutableArray arrayWithContentsOfFile:path];
NSLog(@"data array from offers %@", dataArray);
这是输出:
2013-01-21 15:13:34.599 data array from offers (
{
checked = 1;
text = Provider1;
},
{
checked = 1;
text = Provider2;
},
{
checked = 1;
text = Provider3;
},
{
checked = 1;
text = Provider4;
}
)
所以我希望能够找出每个项目的选中值。 Provider4 设置为 1,Provider3 设置为 0 等等...然后使用它来将参数传递给字符串。
最佳答案
NSString *path = [[NSBundle mainBundle] pathForResource:@"Providers" ofType:@"plist"];
dataArray = [NSMutableArray arrayWithContentsOfFile:path];
for (NSDictionary *dictionary in dataArray)
{
NSString *text = [dictionary valueForKey:@"text"];
NSNumber *checked = [dictionary valueForKey:@"checked"];
NSLog(@"%@ checked value is: %@", text, checked);
}
关于iphone - 如何从 plist 加载值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14441821/