2011-07-23 38 views
-2

我創建了一個plist,並通過直接修改myPlist.plist文件填充數據。我如何從中讀取值並在輸出中顯示它們。 我正在使用分組表格,我想填充我之前創建的plist單元格的數據。 有何建議?Plist - iPhone開發

+0

查看我的回答。希望對你有所幫助。 – booleanBoy

+0

對不起,我無法在答案中正確格式化代碼。 – booleanBoy

+2

-1老兄看看這個鏈接http://www.google.com/search?q=read+values+from+plist+&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-US:官方&客戶端= firefox-a – Aravindhan

回答

1

如果要存儲的內容作爲一個NSDictionary,那麼這是怎麼了,你必須從plist中訪問:

NSString *myFile = [[NSBundle mainBundle] pathForResource:@"myList" ofType:@"plist"]; 
NSMutableDictionary* myDict = [[NSMutableDictionary alloc]initWithContentsOfFile:myFile]; 
NSLog(@"%@", myDict); 

獲取陣列中的數據,如果你已經存儲的數據作爲NSArray。 要在的tableview使用顯示它下面的代碼:

cell.textLabel.text = [myArray objectAtIndex:indexPath.row]; 

寫上面的代碼內-tableView:cellForRowAtIndexPath:方法。

+0

只要頂層對象是一個數組,字典或集合,這將與用plist編輯器創建的plist一起工作。 – TechZen