I can't get image from PFFile

為{幸葍}努か 提交于 2020-02-02 14:01:38

问题


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;
}

回答1:


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.



来源:https://stackoverflow.com/questions/27492861/i-cant-get-image-from-pffile

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!