简体   繁体   中英

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.

This works

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

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

    [cell.imageView loadInBackground];

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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