我从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结构:
答案 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"]];