PFQueryTableViewController没有加载图片parse.com

时间:2014-02-21 13:09:31

标签: ios uitableview parse-platform pfquery

目前,我正在使用以下代码:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath object:(PFObject *)object {

static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier     forIndexPath:indexPath];

if (!cell) {
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}



PFFile *file = [object valueForKeyPath:@"exercicio.foto"];
[file getDataInBackgroundWithBlock:^(NSData *data, NSError *error) {
    cell.imageView.image = [[UIImage alloc] initWithData:data];
    [cell setNeedsLayout];
}];

return cell;
}

这样可以,但是图像加载时间太长,滚动时视觉效果不太好。我尝试使用PFTableViewCell,但是当我尝试从解析中获取我的PFFile时,我收到消息,无法识别的选择器发送到行cell.imageView.file中的实例。现在,当我将故事板中的类更改为PFTableViewCell时,应用程序不会崩溃,但也不会加载任何图像。

这是给我崩溃的代码,或者如果我将故事板更改为PFTableViewCell,它不会显示图像。

- (PFTableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath object:(PFObject *)object {

static NSString *CellIdentifier = @"Cell";
PFTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier    forIndexPath:indexPath];

if (!cell) {
    cell = [[PFTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault     reuseIdentifier:CellIdentifier];
}
cell.imageView.file = [object valueForKeyPath:@"exercicio.foto"];

return cell;
}

我真的需要帮助,我尝试过很多东西,但似乎没什么用。感谢。

3 个答案:

答案 0 :(得分:1)

这有效

PFFile *thumbnail = object[@"imageFile"];

    cell.imageView.image = [UIImage imageNamed:@"857-rocket.png"];
    cell.imageView.file = thumbnail;

    [cell.imageView loadInBackground];

答案 1 :(得分:0)

如果问题是您的图片需要很长时间才能加载,我建议您创建图片的缩略图版本,然后在tableview中使用它们。然后,如果从tableview转到详细视图,则加载完整大小的图像。

答案 2 :(得分:0)

设置PFImageView的文件值

后,必须调用loadInBackground
- (void)loadInBackground

文件属性的解析文档描述确认:

  

Parse服务器上存储图像的远程文件。请注意   在调用loadInBackground:之前,下载才会启动。

还有一个带完成块的方法:

- (void)loadInBackground:(void ( ^ ) ( UIImage *image , NSError *error ))completion
相关问题