繁体   English   中英

将图像从解析加载到图像视图

[英]Loading images from parse to image views

我想从解析中加载图像,如屏幕截图所示。 我的解析

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

        }
        }];
        }
                }
            }];

我的问题是如何将其他三张图片同样加载到图片视图中?

实现延迟加载图像。 例如-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;
                        }
                   });
}];

希望对您有帮助,以最快的速度解决您的问题

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM