我有一個包含國家,州,城市的plist文件。我可以進入採購員的國家級別,但我似乎無法獲得州和市人口。我創建了一個plist文件,內容如下:country - > dictionary,state - > dictionary和city - > array。在我的plist文件中訪問兩個級別
的代碼是:
NSBundle *bundle = [NSBundle mainBundle];
NSString *plistPath = [bundle pathForResource:@"placesdictionary" ofType:@"plist"];
NSDictionary *dictionary = [[NSDictionary alloc] initWithContentsOfFile:plistPath];
self.places = dictionary;
NSArray *componentsCountry = [self.places allKeys];
NSArray *sortedCountry = [componentsCountry sortedArrayUsingSelector:@selector(compare:)];
self.country = sortedCountry;
NSString *selectedCountry = [country objectAtIndex:0];
這是好的。但下面的代碼有錯誤:
NSArray *componentsState = [self.places allKeysForObject:selectedCountry];
NSArray *sortedState = [componentsState sortedArrayUsingSelector:@selector(compare:)];
self.state = sortedState;
NSString *selectedState = [state objectAtIndex:0];
NSArray *componentsCity = [self.places objectForKey:selectedState];
NSArray *sortedCity = [componentsCity sortedArrayUsingSelector:@selector(compare:)];
self.city = sortedCity;
你能幫我解決這個問題嗎?謝謝。
這是我的plist文件:
<?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">
<dict>
<key>France</key>
<dict>
<key>state 3</key>
<array>
<string>Paris</string>
</array>
<key>state 2</key>
<array>
<string>Nice</string>
</array>
</dict>
<key>US</key>
<dict>
<key>california</key>
<array>
<string>LA</string>
<string>San Fran</string>
<string>San Diego</string>
</array>
<key>new jersey</key>
<array>
<string>riverdale</string>
<string>newark</string>
</array>
</dict>
</dict>
</plist>
國家,州,城市 - 都在你的plist一個水平?或國家在國內? – Nekto
這是plist文件: –
<?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 「> \t 法國 \t \t \t 狀態3 \t \t \t \t \t 巴黎 \t \t \t \t 狀態2 \t \t \t \t \t 尼斯 \t \t \t \t 美國 \t \t \t 加州 \t \t \t \t \t LA \t \t \t 聖弗蘭 \t \t \t 聖地亞哥 \t \t \t –