1

私はこれに1か月以上苦労していたので、自分で解決しようとしました。

アイテムの辞書を含むリストの plist があります。たとえば、買い物リストのアイテムのチェック済みステータスを表示するためにドリルダウンするにはどうすればよいですか?

<dict>
<key>Shopping List</key>
<array>
    <dict>
        <key>Name</key>
        <string>Green Tea</string>
        <key>Checked</key>
        <false/>
    </dict>
    <dict>
        <key>Name</key>
        <string>Tempeh</string>
        <key>Checked</key>
        <false/>
    </dict>
    <dict>
        <key>Name</key>
        <string>Kimuchi</string>
        <key>Checked</key>
        <false/>
    </dict>
    <dict>
        <key>Name</key>
        <string>Jasmine Rice</string>
        <key>Checked</key>
        <false/>
    </dict>
</array>
<key>To-Do List</key>
<array>
    <dict>
        <key>Name</key>
        <string>Wash Car</string>
        <key>Checked</key>
        <false/>
    </dict>
    <dict>
        <key>Name</key>
        <string>Run Diswasher</string>
        <key>Checked</key>
        <false/>
    </dict>
</array>

4

2 に答える 2

0

これを試して :

// First we get the path for the plist
NSString *thePath = [[NSBundle mainBundle] pathForResource:@"PlistFileName" ofType:@"plist"]; // Replace PlistFileName with your plist name (without its file extension)

// Then, we get the first dictionary (containing "Shopping List" and "To-Do List") 
NSDictionary *listsDictionary = [[NSDictionary alloc] initWithContentsOfFile:thePath];

// Then, we get the array contained in the "Shopping List" object of the previous dictionary we got
NSArray *theShoppingList = [listsDictionary objectForKey:@"Shopping List"];

// Then, we get the dictionary representing an item of the list at a given index in the previous array we got
NSDictionary *item = (NSDictionary *)[theShoppingList objectAtIndex:index]; // index represents the index of the item in the plist

// Last but not least, we get the Checked value (as a boolean value) contained in the item
Boolean checked = [[item objectForKey:@"Checked"] boolValue];
于 2013-09-04T21:55:30.260 に答える