我无法从PFFile获得图像

时间:2014-12-15 20:48:11

标签: ios objective-c parse-platform pffile

Parse.com刚刚更新了他们的SDK以支持本地存储。但是在安装新的SDK之后,我发现了PFFile的一些问题。我已经使用了相同的方法很长一段时间,但现在我使用新的SDK我无法使其工作。

这是我的代码:

.h文件

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

.m文件

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;

   }];

当我跑步时,我得到these errors (link)

其他人是否有同样的问题?

更新

- (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 个答案:

答案 0 :(得分:1)

我自己找到了解决方案。

 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;

}];

这将加载图像。 奇怪的是它不会在模拟器中运行..但在iPhone上完美运行。