2014-05-13 58 views
0

我試圖從plist中獲取子元素SHOP。 plist中是像這樣:從pList獲取對象數據並填充到cellForIndexPath中

enter image description here

設置是一個截面。

我嘗試使用以下,但不知道如何把它放在一個cellForIndexPath

NSDictionary *region = [self.dict valueForKey:@"Settings"]; 
NSString *name = [region valueForKey:@"Shop"]; 
NSLog(@"%@", name); 

我的plist是像這樣:

NSString *path = [[NSBundle mainBundle] pathForResource:@"PropertyList" ofType:@"plist"]; 
NSDictionary *tempDict = [[NSDictionary alloc] initWithContentsOfFile:path]; 

self.dict = tempDict; 

NSArray *tempArray = [[NSArray alloc] init]; 
self.namesArray = tempArray; 

self.sectionArray = [self.dict allKeys]; 
+0

'Settings'是一個數組,但是您正在向它發送'-objectForKey:'。它必須崩潰。 – Michael

+0

我怎麼會把它放在cellforindexpath中? –

回答

0

如果你需要的是閱讀「店「 array 」item 0「字典您需要做以下幾項:

NSString *path = [[NSBundle mainBundle] pathForResource:@"PropertyList" ofType:@"plist"]; 
NSDictionary *tempDict = [[NSDictionary alloc] initWithContentsOfFile:path]; 

self.dict = tempDict; 

NSArray *settingsArray = self.dict[@"Settings"]; 
NSDictionary *itemDict = settingsArray[0]; 
NSArray *shopArray = itemDict[@"Shop"]; 

當然,您應該在編制索引之前檢查您使用的鍵和索引是否有效,以避免崩潰。