【问题标题】:I can't get image from PFFile我无法从 PFFile 获取图像
【发布时间】:2015-02-14 01:39:59
【问题描述】:

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

【问题讨论】:

  • 哦,你刚刚换了屏幕截图……而且屏幕截图中的代码和这里的代码不一样……
  • 您正在结合两个不同的概念...如果您使用的是 PFImageView,则无需使用getDataInBackground
  • 您刚刚删除了您的评论... PFImageView 是哪个?
  • @LyndseyScott 抱歉,我把截图弄混了。我现在已经修好了。
  • PFImageView 是什么?

标签: ios objective-c parse-platform pffile


【解决方案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 上完美运行。

【讨论】:

  • 我不知道你为什么在块内有占位符图像。
猜你喜欢
  • 1970-01-01
  • 2012-06-12
  • 2020-10-22
  • 1970-01-01
  • 2014-12-21
  • 1970-01-01
  • 2022-01-20
  • 2017-01-29
  • 2018-01-01
相关资源
最近更新 更多