2

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

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

我真的需要帮助,我已经尝试了很多东西,但似乎没有任何效果。谢谢。

4

3 回答 3

1

这有效

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

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

    [cell.imageView loadInBackground];
于 2014-07-31T02:27:21.363 回答
0

设置 PFImageView 的文件值后,您必须调用 loadInBackground

- (void)loadInBackground

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

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

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

- (void)loadInBackground:(void ( ^ ) ( UIImage *image , NSError *error ))completion
于 2014-02-28T15:38:38.817 回答
0

If the problem is that your images take too long to load, I would recommend you create thumbnail versions of your images and then use those in the tableview. Then, if you go from tableview to a detail-view, you load the full size image.

于 2014-02-28T13:04:49.007 回答