简体   繁体   English

PFQueryTableViewController不加载图像parse.com

[英]PFQueryTableViewController not loading images parse.com

At the moment, I'm using the following code: 目前,我正在使用以下代码:

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

This works, but the images take too long to load, and visual effects are not so good when scrolling. 此方法有效,但是图像加载时间太长,滚动时的视觉效果也不太好。 I tried to use PFTableViewCell, but I get the message, unrecognized selector sent to instance in the line cell.imageView.file when I try to get my PFFile from parse. 我尝试使用PFTableViewCell,但是当我尝试从解析中获取PFFile时,却收到消息,无法识别的选择器发送至cell.imageView.file行中的实例。 Now, when I change the class in storyboard to PFTableViewCell, app doesn't crash, but no images are loaded as well. 现在,当我将情节提要中的类更改为PFTableViewCell时,应用程序不会崩溃,但也不会加载任何图像。

This is the code that gives me crash or in case I change storyboard to PFTableViewCell, it doesn't show the images. 这是使我崩溃的代码,或者如果我将情节提要更改为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;
}

I really need help with this, I've tried a lot of things but nothing seems to work. 我确实需要帮助,我尝试了很多事情,但似乎没有任何效果。 Thanks. 谢谢。

This works 这有效

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

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

    [cell.imageView loadInBackground];

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. 然后,如果您从表格视图转到详细视图,则会加载完整尺寸的图像。

You have to call loadInBackground after setting the file value of your PFImageView 设置PFImageView的文件值后,必须调用loadInBackground

- (void)loadInBackground

Parse docs description for the file attribute confirms that : 解析文件属性的文档说明可以确认:

The remote file on Parse's server that stores the image. Parse服务器上存储图像的远程文件。 Note that the download does not start until loadInBackground: is called. 请注意,直到调用loadInBackground:才开始下载。

There is also a method with a completion block : 还有一个带有完成块的方法:

- (void)loadInBackground:(void ( ^ ) ( UIImage *image , NSError *error ))completion

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM