Search code examples
iosobjective-cimageparse-platformnsdata

How to get thumbnail image from parse, objective c


I want to get thumbnail image or blank image first while app is loading image data from parse database. After finish loading, the image view will display the image I load from parse. So far, I have following codes

PFFile *thumbnail = object1[@"PostFiles"];
NSData *imageData = [thumbnail getData];
UIImage *image = [UIImage imageWithData: imageData];

I use PFtableviewcontroller. when I scroll down, my code will load image, the controller can't move smoothly.


Solution

  • The issue is that you are running a synchronous call for a task that could take a varying amount of time. Try getting the NSData using InBackgroundWithBlock:

                 image = nil; //prevent images from being shown erroneously
                 [thumbnail getDataInBackgroundWithBlock:^(NSData *data, NSError *error) {
                        if (data && !error) {
                            image = [UIImage imageWithData:data];
                        } else {
                            //maybe set a default image here if there is none?
                        }
                    }];