2013-11-26 44 views
0

我有一个mapview,显示从解析中拉出的注释数组。每个人都有一个详细的视图控制器,显示连接到注释的标签,我想要显示图像,但似乎无法弄清楚。这是我目前的代码通过解析显示图像iOS

- (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

的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; 
     } 
    }]; 

}]; 
0

我的建议对从解析加载图像:使用imgView作为子文件通过Parse提供的PFImageView的屁股来加载图像并分配给imageView。在这种情况下,你可以简单地分配图像象下面这样:

PFImageView * imgView = [[PFImageView alloc] init];
imgView = [UIImage imageNamed:@"..."]; // placeholder image
imgView.file = [gameScore objectForKey:@"image"];
[imgView loadInBackground];

https://www.parse.com/docs/ios_guide#ui-imageview/iOS

0

以上所有的解决方案是正确的,但要添加一个另一种方式来得到支持SDWebImage或任何的图像缓存的像那样的图书馆。

我已经回答了类似的问题。看一下 https://stackoverflow.com/a/28761476/2225439