为什么不显示图像?

时间:2012-05-23 16:48:26

标签: ios xcode image plist

我从plist文件加载注释,我还需要从plist文件读取图像的图像。

我尝试了以下代码,但它不起作用。

NSString *path = [[NSBundle mainBundle] pathForResource:@"data" ofType:@"plist"];
    NSDictionary *dict = [NSDictionary dictionaryWithContentsOfFile:path];
    NSArray *anns = [dict objectForKey:@"Category1"];
    pinView.image = [UIImage imageNamed:[[dict objectForKey:anns] valueForKey:@"Icon"]];

我的plist结构:

plist

1 个答案:

答案 0 :(得分:0)

这看起来不对:

NSArray *anns = [dict objectForKey:@"Category1"];
pinView.image = [UIImage imageNamed:[[dict objectForKey:anns] valueForKey:@"Icon"]];
                                                        ^^^^

anns是一个数组,所以它不能是你词典的关键。我的猜测是你想要这个:

NSArray *anns = [dict objectForKey:@"Category1"];
pinView.image = [UIImage imageNamed:[[anns objectAtIndex:0] objectForKey:@"Icon"]];