2013-07-29 100 views
0

我想從解析中加載圖像,如您在屏幕截圖中所看到的。 my parse將圖像從解析加載到圖像視圖

我使用此代碼將標題圖像加載到我的imageview中。

PFQuery *query = [PFQuery queryWithClassName:@"AppOfTheDay"]; 
[query getObjectInBackgroundWithId:@"WDJpxs4PzH" 
      block:^(PFObject *retreive, NSError *error) { 
       { 
    NSString *text = [retreive objectForKey:@"description"]; 
if (error) { 
    [MBProgressHUD hideHUDForView:self.view animated:YES]; 
      UIAlertView *error=[[UIAlertView alloc]initWithTitle:@"Error" message:@"Connection Failed" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil]; 
      [error show]; 

     } 
     else{ 
    PFFile *imageFile = [retreive objectForKey:@"header"]; 
     [imageFile getDataInBackgroundWithBlock:^(NSData *data, NSError *error) { 

    if (error) { 
    [MBProgressHUD hideHUDForView:self.view animated:YES]; 
     UIAlertView *error=[[UIAlertView alloc]initWithTitle:@"Error" message:@"Something went wrong" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil]; 
       [error show]; 
    } 
    else{ 
     UIImage *image = [UIImage imageWithData:data]; 
     _headerImage.image=image; 
     _appDescription.text=text; 
    [MBProgressHUD hideHUDForView:self.view animated:YES]; 

     } 
     }]; 
     } 
       } 
      }]; 

我的問題是我怎樣才能同樣地加載我的其他三個圖像到圖像?

回答

0

實現延遲加載圖像。例如,例如: -NSURL * url = [NSURL URLWithString:urlString];

NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url]; 
if (queue == nil) 
{ 
    queue = [[NSOperationQueue alloc] init]; 
} 
[NSURLConnection sendAsynchronousRequest:urlRequest queue:queue completionHandler:^(NSURLResponse * resp, NSData  *data, NSError *error) 
{ 
    dispatch_async(dispatch_get_main_queue(),^ 
        { 
         if (error == nil && data) 
         { 
          UIImage *urlImage = [[UIImage alloc] initWithData:data]; 
          thumbnail.image = urlImage; 
         } 
        }); 
}]; 
0

我希望它會幫助你很多,它會用排序最好的加載速度您的問題

//yourclass.h

AsyncImageView *imageasy,*imageasy1, *imageasy2,imageasy3; 

yourclass.m

 PFQuery *query = [PFQuery queryWithClassName:@"AppOfTheDay"]; 
     [query getObjectInBackgroundWithId:@"WDJpxs4PzH" 
     block:^(PFObject *comment, NSError *error) { 
     if (!error) { 
       PFFile *post = [comment objectForKey:@"PhotoName"]; 
       PFFile *post2 = [comment objectForKey:@"logo"]; 
       PFFile *post3 = [comment objectForKey:@"similar1"]; 
       PFFile *post4 = [comment objectForKey:@"similar2"]; 
       imageasy=[[AsyncImageView alloc] init]; 
       imageasy1=[[AsyncImageView alloc] init]; 
       imageasy2=[[AsyncImageView alloc] init]; 
       imageasy3=[[AsyncImageView alloc] init]; 
       [imageasy setImageURL:[NSURL URLWithString:[post url]]]; 
       [imageasy1 setImageURL:[NSURL URLWithString:[post2 url]]]; 
       [imageasy2 setImageURL:[NSURL URLWithString:[post3 url]]]; 
       [imageasy3 setImageURL:[NSURL URLWithString:[post4 url]]]; 
     }]; 
+0

我我會試試這個。 – Machete

+0

我第一次看到這個AsyncImageView * imageasy = [[AsyncImageView alloc] init];我有我的imageviews.outs不知道如何使用它們在這裏? – Machete

+0

https://github.com/nicklockwood/AsyncImageView你可以下載AsyncImageView.h和.m類到你的項目中,這對減少圖像的加載是非常有用的,而不是使用uiimageview你可以這樣做,例如: - AsyncImageView * imageasy3 = [[AsyncImageView alloc] init];通俗地說,如果你創建uiimageview,你會像這樣分配UIImageView * imageasy3 = [[UIImageView alloc] init]; – Romance

相關問題