0
我試圖從一個plist中是字典的陣列顯示數據:從plist中加載detailviewcontroller中的數據?
<array>
<dict>
<key>title</key>
<string>RATATOUILLE</string>
<key>coverImage</key>
<string>rat.png</string>
<key>smallImage</key>
<string>rat-small.png</string>
<key>description</key>
<string>Spray a pan with cooking spray. Brown the onion and the garlic (do not let garlic burn!). Add all the veggies and the bay leaf and simmer covered for 2 hours. Sprinkle on the breadcrumbs and cook another 5 minutes. Remove the bay leaf and serve.
5 servings, 0 POINTS each (if you eat the whole thing, count points for the bread crumbs)</string>
</dict>
在RootViewController的數據顯示剛在細胞中細
。在detailviewcontroller我已經嘗試了相同的方法,它不顯示任何東西。我究竟做錯了什麼? 下面的代碼:
- (void)viewDidLoad {
[super viewDidLoad];
NSDictionary *details = [NSDictionary dictionaryWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Testdata" ofType:@"plist"]];
coverImageView.image = [UIImage imageNamed:[details objectForKey:@"coverImage"]];
titleLabel.text = [details objectForKey:@"title"];
}
什麼,我不明白的是,它實際上是如何工作的。在RootViewController的我有這樣的方法:
-(id)initWithCoder:(NSCoder *)aDecoder {
if (self = [super initWithCoder:aDecoder]) {
NSString *path = [[NSBundle mainBundle] pathForResource:@"TestData" ofType:@"plist"];
arrayIndex = [[NSArray alloc] initWithContentsOfFile:path];
}
return self;
}
和數據從「arrayIndex」拉。 detailviewcontroller不一樣嗎? ................... 編輯: 我想通了,做在tableviewcontroller的字符串:
NSString *selectedItem = [arrayIndex objectAtIndex:indexPath.row];
detailViewController.selectedItem = selectedItem;
並加載數據的detailviewcontroller像這個:
coverImageView.image = [UIImage imageNamed:[selectedItem valueForKey:@"coverImage"]];
titleLabel.text = [selectedItem valueForKey:@"title"];
請告訴你在「細節」字典中得到什麼...... – objectivecdeveloper