【问题标题】:Loading images from parse to image views将图像从解析加载到图像视图
【发布时间】:2013-07-29 14:37:02
【问题描述】:

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

我正在使用此代码将标题图像加载到我的图像视图中。

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

        }
        }];
        }
                }
            }];

我的问题是如何将其他三张图片类似地加载到 imageviews 中?

【问题讨论】:

    标签: iphone ios parsing ios4


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

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

      //你的类.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]]];
             }];
      

      【讨论】:

      • 我要试试这个。
      • 我第一次看到这个 AsyncImageView *imageasy=[[AsyncImageView alloc] init];我有我的 imageviews 的插座。我不知道如何在这里使用它们?
      • github.com/nicklockwood/AsyncImageView你可以将AsyncImageView.h和.m类下载到你的项目中,这对减少图像的加载很有用,你可以这样代替uiimageview,例如:-AsyncImageView *imageasy3=[[AsyncImageView alloc] 初始化];一般来说,如果你创建 uiimageview,你会像这样分配 UIImageView *imageeasy3=[[UIImageView alloc] init];
      • 实际上我的应用程序主屏幕上有四个图像视图。这将如何将所需的图像加载到我的图像视图中?
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-09-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-12
      • 2015-11-04
      相关资源
      最近更新 更多