1

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;

   }];

当我运行时,我得到这些错误(链接)

其他人有同样的问题吗?

更新:

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

1 回答 1

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 上完美运行。

于 2014-12-16T08:06:48.353 回答