我有一个mapview,显示从解析中提取的一系列注释。每个都有一个细节视图控制器,显示连接到注释的标签,我试图显示一个图像,但似乎无法搞清楚。这是我目前的代码
- (void)viewDidLoad
{
[super viewDidLoad];
PFObject *gameScore = [PFObject objectWithClassName:@"Arcade"];
self.title = @"Detail View";
PFQuery *query = [PFQuery queryWithClassName:@"Arcade"];
NSString *objectId = gameScore.objectId;
[query getObjectInBackgroundWithId:ObjectIdentifier block:^(PFObject *gameScore, NSError *error) {
lblTitle.text = pawpost.title;
lblPhone.text = pawpost.phone;
lblAddress.text = pawpost.address;
__block UIImage *MyPicture = [[UIImage alloc]init];
PFFile *imageFile = [gameScore objectForKey:@"image"];
[imageFile getDataInBackgroundWithBlock:^(NSData *data, NSError *error){
if (!error) {
MyPicture = [UIImage imageWithData:data];
}
}];
imgView.image = MyPicture;
}];
}
我运行它时没有给我任何错误,但它根本不显示..有什么建议吗?
答案 0 :(得分:0)
getDataInBackgroundWithBlock是异步执行的,包含这一行的块:
MyPicture = [UIImage imageWithData:data];
可能在
之后完成imgView.image = MyPicture;
尝试类似:
[query getObjectInBackgroundWithId:ObjectIdentifier block:^(PFObject *gameScore, NSError *error) {
lblTitle.text = pawpost.title;
lblPhone.text = pawpost.phone;
lblAddress.text = pawpost.address;
__block UIImage *MyPicture = [[UIImage alloc]init];
PFFile *imageFile = [gameScore objectForKey:@"image"];
[imageFile getDataInBackgroundWithBlock:^(NSData *data, NSError *error){
if (!error) {
MyPicture = [UIImage imageWithData:data];
imgView.image = MyPicture;
}
}];
}];
答案 1 :(得分:0)
我建议从解析加载图像:使用imgView
作为PFImageView的子类,由Parse提供加载图像并分配给imageView。在这种情况下,您可以简单地分配如下图像:
PFImageView * imgView = [[PFImageView alloc] init];
imgView = [UIImage imageNamed:@"..."]; // placeholder image
imgView.file = [gameScore objectForKey:@"image"];
[imgView loadInBackground];
答案 2 :(得分:0)
以上所有解决方案都是正确的,但是想要添加另一种方法来支持SDWebImage的图像缓存或任何类似的库。
我已经回答了类似的问题。看一看 https://stackoverflow.com/a/28761476/2225439