1

所以我对 Xcode 和 C# 还很陌生,所以这可能是一个愚蠢的问题,但尽管如此,它让我现在已经把头发扯掉了 3 天。

好的,所以我使用 Parse 来获取和保存数据、图像等。我想显示一个带有 PFFile 图像的 UITableView。这一点我已经做到了。

我遇到的问题是滚动性能很差,因为我没有缓存传入的 PFFile 图像。我不知道如何执行此操作,并且我进行的任何搜索都没有考虑使用解析。

下面是我将初始数据放入数组的代码:

-(无效)retrieveFromParse {

PFQuery *retrieveContent = [PFQuery queryWithClassName:@"NewsFeed"];
[retrieveContent orderByDescending:@"createdAt"];
//[retrieveContent unpinInBackground];
//retrieveContent.cachePolicy = kPFCachePolicyCacheElseNetwork;


[retrieveContent findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {


    if(!error){
        mainArray = [[NSArray alloc] initWithArray:objects];

    }

    [tableView reloadData];


}];

}

然后此代码获取图像:

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

static NSString *CellIdentifier = @"MyCell";

TableCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

cell.profilePicture.layer.cornerRadius = cell.profilePicture.frame.size.height /1.99;
cell.profilePicture.layer.masksToBounds = YES;
cell.profilePicture.layer.borderWidth = 0;


PFObject *imageObject = [mainArray objectAtIndex:indexPath.row];
PFFile *imageFile = [imageObject objectForKey:@"image"];

[imageFile getDataInBackgroundWithBlock:^(NSData *data, NSError *error) {
    if(!error){

        NSLog(@"%@",data);

        cell.myImage.image = [UIImage imageWithData:data];

    }

}];


return cell;

}

现在,您会看到我已经注释掉了 cachePolicy,因为每次我使用它时,线程都会中断。

如果有人可以更改我的代码或使用我的代码为我提供示例项目,以考虑缓存数组和/或 PFFile 图像,这将使我免于秃顶!:)

提前谢谢了。

4

1 回答 1

0

您是否尝试在 viewdidload 函数而不是 cellForRowAtIndexPath 中检索图像?

我之前遇到过同样的问题,我通过执行以下操作解决了几乎 90% 的问题:

1- 在 vi​​ewdidload 中,我写了 2 个查询:1 个用于检索数据,另一个用于检索图像并将它们存储在一个数组中。2- 在 cellForRowAtIndexPath 中,我刚刚添加了我在视图中获得的图像确实加载到了我的单元格中。

这就是我所做的,但不幸的是我仍然遇到问题。问题是图像的检索顺序与检索数据“图像未显示在正确数据旁边:/”的顺序不同。我正在尝试解决这个问题,如果我这样做了,我会发布解决方案:)

希望我的解决方案对您有所帮助。祝你好运 ;)

于 2015-03-30T08:35:03.553 回答