1
用了大概使用stackoverflows搜索一個星期,但沒有運氣...訪問值不同的密鑰
以下是我有:
1的plist:
<plist version="1.0">
<array>
<dict>
<key>name</key>
<string>Name 1</string>
<key>abrev</key>
<string>(HGB, ΗbA)</string>
<key>picture</key>
<string>first.png</string>
<key>pictureHeight</key>
<integer>1686</integer>
</dict>
<dict>
<key>name</key>
<string>Name 2</string>
<key>abrev</key>
<string> </string>
<key>picture</key>
<string>second.png</string>
<key>pictureHeight</key>
<string>396</string>
</dict>
<dict>
...
<dict>
</array>
</plist>
的問題是:
如何知道鍵「name」的值的鍵「圖片」和「pictureHeight」
的值。
我想這樣的事情,不過,迫切失敗...
//creating an array that contains the plist
dictArray = [[NSArray alloc] initWithContentsOfFile:[[NSBundle mainBundle]
pathForResource:@"table1" ofType:@"plist"]];
//creating an array that contains only the vlaues for key "name"
NSMutableArray *temp = [dictArray valueForKey:@"name"];
//searchedData - an NSMutableArray containing the "name" values that
//the user searched using the searchbar
for (i=0; i<[searchedData count]; ++i)
{
if ([searchedData containsObject:[temp objectAtIndex:i]])
{
[temp removeObjectAtIndex:i];
}
}
最後我有鑰匙「名稱」值的數組,我需要獲得「圖片」和「pictureHeight」推動所有這些信息來下一個視圖控制器...
我正在尋找任何新的想法(或者教程),因爲我沒有得到與我太遠...
Caleb!謝謝你爲了完美的答案而努力!我查了一些有關NSpredicate的信息,這正是我錯過的!我甚至會檢查我的其他所有應用程序以使用它優化代碼。這真的是一個非常強大的東西!祝你好運,再次感謝你指引我朝這個方向發展!附:額外的感謝您的第二個決定!:) – 2011-03-08 22:42:33
太好了 - 我很高興我能幫上忙。 ;-) – Caleb 2011-03-08 22:53:26
你也可以使用d [@「name」] replace [d objectForKey:@「name」]。 – 2013-01-11 03:48:14