I cannot get image from PFFile

Parse.com just updated their SDKs to support local storage. But after installing the new SDKs, I ran into some problems with PFFile. I have been using the same method for a long time, but now that I am using the new SDK, I cannot get it to work.

Here's my code:

.h file

@property (strong, nonatomic) IBOutlet PFFile *iconPhoto;

      

.m file

cell.iconPhoto.image = [UIImage imageNamed:@"placeholder.png"]; // placeholder image
cell.iconPhoto.file = (PFFile *)object[@"icon"]; // remote image
[cell.iconPhoto loadInBackground:^(UIImage *image, NSError *error) {
    cell.iconPhoto.image = image;
    cell.userInteractionEnabled = YES;

   }];

      

When I run I get these errors (link)

Does anyone have other problems?

UPDATE:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{

    });

    static NSString *CellIdentifier = @"Cell";
    MainTVCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
    PFObject *object = [self.currentCategories objectAtIndex:indexPath.row];

    cell.mainLabel.text = object[@"name"];
    cell.userInteractionEnabled = YES;

    if (![object[@"icon"] isEqual:[NSNull null]]) {

        cell.image = [UIImage imageNamed:@"loading.png"]; // placeholder image
        cell.iconPhoto = (PFFile *)object[@"icon"]; // remote image
        [cell.iconPhoto getDataInBackgroundWithBlock:^(NSData *imageData, NSError *error) {
            if (!error && imageData) {
                cell.image = [UIImage imageWithData:imageData];
                cell.userInteractionEnabled = YES;
            }

        }];


    }

    return cell;
}

      

+1


source to share


1 answer


I found a solution myself.

 PFFile *file = (PFFile *)object[@"icon"];
[file getDataInBackgroundWithBlock:^(NSData *data, NSError *error) {

    cell.iconImageView.image = [UIImage imageNamed:@"placeholder.png"]; // placeholder image
    cell.iconImageView.image = [UIImage imageWithData:data];
    cell.userInteractionEnabled = YES;

}];

      



This will load the images. It's weird that it won't work in the simulator. But works great on iPhone.

+1


source







All Articles