目前,我使用以下代码:
- (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,但当我试图从parse中获取PFFile时,我收到消息,无法识别的选择器被发送到cell.imageView.file行中的实例。现在,当我将storyboard中的类更改为PFTableViewCell时,应用程序不会崩溃,但也不会加载图像。
这是使我崩溃的代码,或者如果我将storyboard更改为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;
}我真的需要帮助,我已经尝试了很多方法,但似乎都不起作用。谢谢。
发布于 2014-07-31 10:27:21
这是可行的
PFFile *thumbnail = object[@"imageFile"];
cell.imageView.image = [UIImage imageNamed:@"857-rocket.png"];
cell.imageView.file = thumbnail;
[cell.imageView loadInBackground];发布于 2014-02-28 21:04:49
如果问题是您的图像加载时间太长,我建议您创建图像的缩略图版本,然后在表视图中使用这些图像。然后,如果您从表视图转到细节视图,则会加载完整大小的图像。
发布于 2014-02-28 23:38:39
在设置PFImageView的文件值之后,必须调用loadInBackground
- (void)loadInBackground解析文件属性的文档描述确认:
解析器服务器上存储图像的远程文件。请注意,在调用loadInBackground:之前,下载不会开始。
还有一个带有完成块的方法:
- (void)loadInBackground:(void ( ^ ) ( UIImage *image , NSError *error ))completionhttps://stackoverflow.com/questions/21935386
复制相似问题