2011-02-03 76 views
2

的字符串我有以下結構的plist:獲取的NSDictionary

<?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> 
<plist version="1.0"> 
<array> 
    <dict> 
     <key>height</key> 
     <real>2075</real> 
     <key>name</key> 
     <string>Dublin-Pony-kids-25_thumb</string> 
     <key>width</key> 
     <real>1558</real> 
    </dict> 
    <dict> 
     <key>height</key> 
     <real>2219</real> 
     <key>name</key> 
     <string>Dublin-Pony-kids-26_thumb</string> 
     <key>width</key> 
     <real>1751</real> 
    </dict> 
    <dict> 
     <key>height</key> 
     <real>2532</real> 
     <key>name</key> 
     <string>Dublin-Pony-kids-27_thumb</string> 
     <key>width</key> 
     <real>1732</real> 
    </dict> 
    <dict> 
     <key>height</key> 
     <real>2430</real> 
     <key>name</key> 
     <string>Dublin-Pony-kids-28_thumb</string> 
     <key>width</key> 
     <real>1730</real> 
    </dict> 
</array> 
</plist> 

我不知道如何獲得的NSString所有結果鍵 - >名稱。 我想要有像都柏林小馬-25_thumb,都柏林小馬-26_thumb,都柏林-Pony-kids-27_thumb,都柏林-Pony-kids-28_thumb的東西。

我可以像(NSString *)imageNameAtIndex:(NSUInteger)index { 那樣讀取它,但這隻返回一個值。我希望key-> name的所有值都是NSString

我再次對此有所幫助。

回答

2

如果您加載的plist到一個數組(通過+[NSArray arrayWithContentsOfFile:...]),那麼你應該能夠做到:

NSArray *plistContents = [NSArray arrayWithContentsOfFile:...]; //load the plist into memory 
NSArray *names = [plistContents valueForKey:@"name"]; 
0

感謝你回答。它給了我正確的方式。我這樣稱呼我的拇指。

- (NSArray *)thumbNames { 
//For the thumbs we need a different array than for the images 
//Load the plist 
NSString* plistPath = [[NSBundle mainBundle] pathForResource:@"ImageData" ofType:@"plist"]; 
NSArray *plistContents = [NSArray arrayWithContentsOfFile:plistPath]; //load the plist into memory 
NSArray *thumbNames = [plistContents valueForKey:@"name"]; 


return thumbNames; 

}

的VAR thumbNames現在我可以加載到一個新的觀點。

乾杯

德克