计算plist数组中的项目

时间:2013-11-17 02:15:42

标签: ios plist

我很难访问所选择的plist的数量。在先前的视图控制器中,用户从几个按钮中的一个中选择,每个按钮对应于特定的钳子。该plist作为NSString * chosenPlist发送到当前的vc。我有NSLogged看到文件目录和plistpath似乎是正确的,但我想要计算的数组仍然是0。 如何计算所选plist中的项目数?

NSString * chosenPlistPlus = [chosenPlist stringByAppendingString:@".plist"];

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSLog(@"The documentsdirectory is %@", documentsDirectory);

NSString *myPlistPath = [documentsDirectory stringByAppendingPathComponent:chosenPlistPlus];
NSLog(@"MyPlistPath = %@", myPlistPath);



NSArray *arr = [NSArray arrayWithContentsOfFile: myPlistPath];
//Trying to count the items in the plist, which is an array of dicts.
    int count = arr.count;

NSLog(@"Count is %i", count);

这是一个日志:

2013-11-16 21:13:07.037 GlobalHistoryRegents[70407:70b] The documentsdirectory is /Users/username/Library/Application Support/iPhone Simulator/7.0.3/Applications/896EF347-A35E-40E2-9BE1-8CFAC5303347/Documents
2013-11-16 21:13:07.037 GlobalHistoryRegents[70407:70b] MyPlistPath = /Users/username/Library/Application Support/iPhone Simulator/7.0.3/Applications/896EF347-A35E-40E2-9BE1-8CFAC5303347/Documents/methodologyQuestions.plist
2013-11-16 21:13:07.038 GlobalHistoryRegents[70407:70b] Count is 0

1 个答案:

答案 0 :(得分:0)

尝试使用,

NSDictionary *dictionary = [NSDictionary dictionaryWithContentsOfFile:myPlistPath];
NSArray *arr =dictionary[@"Root"];
相关问题