我想維護一個記錄列表,對於每個維護相同類型的數據。我想在2個不同的地方使用這個數據:從PList獲取數據到UITableView?
UITableView
從每條記錄的「名稱」值UIViewController
這需要所有的數據在不同領域的使用需要。
我假設我應該使用plist來存儲數據;我還假設應該接收UITableView
數據的對象是NSArray
,所以我可以使用cellForRowAtIndexPath
方法自動創建表。
所以我創建plist中「PLForArr.plist」:
看來,我只能得到調用使用
NSString *path = [[NSBundle mainBundle] pathForResource:@"PLForArr" ofType:@"plist"];
NSArray * myArr = [[NSArray alloc] initWithContentsOfFile:path]; //doesn't work...
NSDictionary * myDict = [[NSDictionary alloc] initWithContentsOfFile:path]; //does work, but who to I make a NSArray out of it/or get the data from here to the UITableView?
我明白,我不明白的plist時的NSDictionary一些基本的東西在這裏...能有人把我一步一步:
- 如何保持數據 - S我應該用plist還是別的東西?我是否應該有一個類型數組的主記錄(就像我在這裏的示例plist所做的那樣),還是可以將它保留爲這些字典,而不用我使用的不必要的
MyArr
考慮UITableView
最終目標? - 如何調用數據 - 有沒有辦法讓它進入
NSArray
或必須進入NSDictionary
? - 如何將它調用到UITableView中 - 我可以使用
NSDictionary
填寫行嗎?