iosobjective-cparse-platformpffile

I can't get image from PFFile


Parse.com just updated their SDKs to support local storage. But after installing new SDKs I have occurred some problems with PFFile. I have used the same method for a long time, but now that I'm using the new SDK I can't 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)

Is someone else having the same 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;
}

Solution

  • 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. Weird thing it won't run in the simulator.. But works perfectly on iPhone.