【问题标题】:PFQueryTableViewController not loading images parse.comPFQueryTableViewController 不加载图像 parse.com
【发布时间】:2014-02-21 13:09:30
【问题描述】:

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

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

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

【问题讨论】:

    标签: ios uitableview parse-platform pfquery


    【解决方案1】:

    这行得通

    PFFile *thumbnail = object[@"imageFile"];
    
        cell.imageView.image = [UIImage imageNamed:@"857-rocket.png"];
        cell.imageView.file = thumbnail;
    
        [cell.imageView loadInBackground];
    

    【讨论】:

      【解决方案2】:

      如果问题是您的图像加载时间过长,我建议您创建图像的缩略图版本,然后在表格视图中使用这些版本。然后,如果您从 tableview 转到 detail-view,则加载完整尺寸的图像。

      【讨论】:

        【解决方案3】:

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

        - (void)loadInBackground
        

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

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

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

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

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2016-05-14
          • 1970-01-01
          • 2014-01-24
          相关资源
          最近更新 更多