Jorge
Jorge

Reputation: 1532

PFQueryTableViewController not loading images parse.com

At the moment, I'm using the following code:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath object:(PFObject *)object {

static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier     forIndexPath:indexPath];

if (!cell) {
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}



PFFile *file = [object valueForKeyPath:@"exercicio.foto"];
[file getDataInBackgroundWithBlock:^(NSData *data, NSError *error) {
    cell.imageView.image = [[UIImage alloc] initWithData:data];
    [cell setNeedsLayout];
}];

return cell;
}

This works, but the images take too long to load, and visual effects are not so good when scrolling. I tried to use PFTableViewCell, but I get the message, unrecognized selector sent to instance in the line cell.imageView.file when I try to get my PFFile from parse. Now, when I change the class in storyboard to PFTableViewCell, app doesn't crash, but no images are loaded as well.

This is the code that gives me crash or in case I change storyboard to PFTableViewCell, it doesn't show the images.

- (PFTableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath object:(PFObject *)object {

static NSString *CellIdentifier = @"Cell";
PFTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier    forIndexPath:indexPath];

if (!cell) {
    cell = [[PFTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault     reuseIdentifier:CellIdentifier];
}
cell.imageView.file = [object valueForKeyPath:@"exercicio.foto"];

return cell;
}

I really need help with this, I've tried a lot of things but nothing seems to work. Thanks.

Upvotes: 2

Views: 630

Answers (3)

Atma
Atma

Reputation: 29767

This works

PFFile *thumbnail = object[@"imageFile"];

    cell.imageView.image = [UIImage imageNamed:@"857-rocket.png"];
    cell.imageView.file = thumbnail;

    [cell.imageView loadInBackground];

Upvotes: 1

Michaël Azevedo
Michaël Azevedo

Reputation: 3896

You have to call loadInBackground after setting the file value of your PFImageView

- (void)loadInBackground

Parse docs description for the file attribute confirms that :

The remote file on Parse’s server that stores the image. Note that the download does not start until loadInBackground: is called.

There is also a method with a completion block :

- (void)loadInBackground:(void ( ^ ) ( UIImage *image , NSError *error ))completion

Upvotes: 0

Marius Waldal
Marius Waldal

Reputation: 9942

If the problem is that your images take too long to load, I would recommend you create thumbnail versions of your images and then use those in the tableview. Then, if you go from tableview to a detail-view, you load the full size image.

Upvotes: 0

Related Questions