2013-11-26 48 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