0

我尝试使用以下函数将 plist 文件内容放入数组中:

NSString *path = [[NSBundle mainBundle] pathForResource:@"DataFile" ofType:@"plist"];
self.contentData = [NSArray arrayWithContentsOfFile:path];

但是 self.contentData 一直为空......我不明白为什么。我使用了与 Apple“PageControl”示例项目(参见此处)中显示的代码相同的代码,还使用了具有相同结构的 pList 文件(其中包含 2 个字符串的字典项列表)。

路径填充:/var/Mobile/Applications/somehexvalues/MyApp.app/DataFile.plist

我怎么知道出了什么问题?

NSLog(@"%@", [NSDictionary dictionaryWithContentsOfFile:path]); 给出:

"Item 0" =     {
    imageKey = "hearts.png";
    nameKey = Hearts;
};
"Item 1" =     {
    imageKey = "leef.png";
    nameKey = Leef;
};
"Item 2" =     {
    imageKey = "round.png";
    nameKey = Round;
};
4

1 回答 1

1

你的 PLIST 有一个 NSDitionary 而不是 NSArray,这就是你得到 null 的原因。如果您尝试将 NSArray 加载到 NSDcitionary 中,您也会得到 null。

于 2011-03-20T10:35:06.307 回答