0

これが私のPLISTの構築方法です。

<dict>
<key>level1</key>
<dict>
<key>formation</key>
<dict>
    <key>height</key>
    <integer>34</integer>
    <key>width</key>
    <integer>12</integer>

</dict>
</dict>
</dict>

レベル>フォーメーション>データ

これは私が使用したサンプルコードですが、機能しませんでした。

//init loading from PLIST here, and then associate value.
NSString *pathString=[NSString stringWithFormat:@"%@Levels",targetWorld];
NSString *path = [[NSBundle mainBundle] pathForResource:pathString ofType:@"plist"];
NSString *levelNameNumber = [[NSString alloc] initWithFormat:targetLevel];

NSDictionary *levelsList = [[NSDictionary alloc] initWithContentsOfFile:path];
NSDictionary *level = [levelsList objectForKey:levelNameNumber];

NSEnumerator *levelFormations = [level objectEnumerator];

for( NSDictionary *worldSize in levelFormations )
{
    worldWidth = [[worldSize objectForKey:@"width"] intValue];
    worldHeight = [[worldSize objectForKey:@"height"] intValue];

    NSLog(@"height is %d",worldHeight);
    NSLog(@"width is %d",worldWidth);

}

[levelNameNumber release];
[levelsList release];

このコードの問題は、2番目のforループを実行し、高さと幅の両方をゼロに戻すことです。

何か案が?またはどのように私はそれを適切な方法で行うのですか?

4

2 に答える 2

0

plutilを使用してplistをチェックし、有効な構文があることを確認してください。

詳細はこちら:http ://www.askdavetaylor.com/can_i_check_my_plist_files_in_mac_os_x_for_problems.html

于 2012-05-16T19:36:06.513 に答える
0

levelListのオブジェクトを使用していて、最後にlevelsListをリリースしているため、ディクショナリから取得したレベルオブジェクトもリリースされます。levelListを解放しないか、レベルを保持するか、できればARCの使用を開始する必要があります。

于 2012-05-17T07:57:48.177 に答える