0

この関数を使用して、plist ファイルの内容を配列に入れようとしました。

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

しかし、self.contentData は null のままです...理由がわかりません。Apple の「PageControl」サンプル プロジェクト (ここを参照) に示されているコードと同じコードを使用し、同じ構造 (内部に 2 つの文字列を持つ Dictionary 項目のリスト) を持つ pList ファイルも使用しました。

パスは次のように入力されます: /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 には NSArray ではなく NSDitionary があるため、null になります。NSArray を NSDcitionary にロードしようとすると、同様に null が返されます。

于 2011-03-20T10:35:06.307 に答える