目前,我正在使用以下代码:
- (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;
}
我真的需要帮助,我已经尝试了很多东西,但似乎没有任何效果。谢谢。