0

正如您在屏幕截图中看到的那样,我想从解析加载图像。我的解析

我正在使用此代码将标题图像加载到我的 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];

        }
        }];
        }
                }
            }];

我的问题是我怎样才能将其他三个图像类似地加载到图像视图中?

4

2 回答 2

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;
                        }
                   });
}];
于 2013-07-30T06:26:45.453 回答
0

我希望它会对你有很大帮助,它会以最佳加载速度解决你的问题

//你的类.h

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

你的班级.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]]];
       }];
于 2013-07-30T06:38:15.257 回答