2

In my app, images are being stored on parse. They then get retrieved into an array of PFFiles, however I have to convert them individually to UIImages using this method which takes time.

  PFFile *picture = [pictureArray objectAtIndex:indexPath.row];
[picture getDataInBackgroundWithBlock:^(NSData *data, NSError *error) {

    myimage = [UIImage imageWithData:data];

}];

So I need to store images on parse, and retrieve them, and I don't want to individually convert all of these pictures, I want it all done at once. These are the options I currently see:

  1. Create a loop that loops the code above to convert all the PFFiles to UIImages and add them to an array ready to access.

  2. Find a better way to convert or use PFFiles.

  3. Upload NSData or something else to parse so I don't have to convert the PFFiles.

Can anyone provide me advice or solutions to my problem? As I am presenting a fairly large amount of images in a UICollectionView, I want them to be all loaded at once some how instead of having to load them individually, I want the images in an array ready to go so I can just call:

cell.myimage.image = [pictureArray objectAtIndex:indexPath.row];

and all the images will be loaded instead of waiting for PFFIles to be converted etc.

Josh
  • 745
  • 1
  • 7
  • 22

1 Answers1

2

If you want to present them you should use PFImageView which can load the by itself. It's a subclass of UIImageView and its pretty.

Example:

PFImageView *creature = [[PFImageView alloc] init];
creature.image = [UIImage imageNamed:@”1.jpg”]; // placeholder image
creature.file = (PFFile *)file;
[creature loadInBackground];

If you want to download them for other uses check out this answer.

Community
  • 1
  • 1
Or Ron
  • 2,313
  • 20
  • 34
  • Do I just subclass it, I don't need to add any extra code? – Josh Aug 19 '15 at 08:38
  • @Josh you dont need to subclass it yourself. It is already subclasses. I added a simple code that explain how to achieve that programmatically. – Or Ron Aug 19 '15 at 08:41
  • will this instantly set the `PFFile` or will this require loading time setting the `PFFile` ? – Josh Aug 19 '15 at 08:48
  • PFFile is on parse server so anytime you wish to present it, it will require a loading time. This way offer graceful loading, allows you to put place holder in the image view and handle the downloading itself. If you want batch downloading you can check out the link to the other question (although usually its not common to do with pictures). – Or Ron Aug 19 '15 at 08:50
  • I have already downloaded the file, I just don't want to waste time converting it. So I have the `PFFile` locally, I want to show it instantly instead of taking time for it to load. How can I do this? – Josh Aug 19 '15 at 09:05
  • If you already have the data downloaded you just convert to uiimage like you did in your code. But I think you should reconsider using `PFImageView` it covers most of the cases. – Or Ron Aug 19 '15 at 09:08
  • That doesn't solve my problem. How can I convert the images without having to wait for them to load? or present them as a `PFFile`? – Josh Aug 19 '15 at 09:11
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/87353/discussion-between-or-ron-and-josh). – Or Ron Aug 19 '15 at 09:12