【发布时间】:2011-11-10 10:29:30
【问题描述】:
我正在尝试显示来自字典数组的 plist 中的数据:
<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”中提取的。细节视图控制器不一样吗? ..................... 编辑: 我想通了,在tableviewcontroller中做了一个字符串:
NSString *selectedItem = [arrayIndex objectAtIndex:indexPath.row];
detailViewController.selectedItem = selectedItem;
并像这样在detailviewcontroller中加载数据:
coverImageView.image = [UIImage imageNamed:[selectedItem valueForKey:@"coverImage"]];
titleLabel.text = [selectedItem valueForKey:@"title"];
【问题讨论】:
-
请说出您在“详细信息”字典中得到了什么......
标签: iphone uitableview plist detailsview