【问题标题】:Retrieve images from parse before UITableVIew has loaded?在加载 UITableVIew 之前从解析中检索图像?
【发布时间】:2014-10-28 14:05:57
【问题描述】:

一切正常,只是单元格中的图像在令人不安的延迟后显示。 tableView 完成加载后大约 0.3 秒。我觉得短时间显示一张空白图是相当难看的……

如何使 tableView 在加载来自解析的图像后立即显示(为什么不先从缓存中?)。或者我可以让启动屏幕保持更长时间..? TableView 是应用程序中的初始视图。

queryForTable

- (PFQuery *)queryForTable {
    PFQuery *query = [PFQuery queryWithClassName:self.parseClassName];

    // If no objects are loaded in memory, we look to the cache
    // first to fill the table and then subsequently do a query
    // against the network.
    if ([self.objects count] == 0) {
        query.cachePolicy = kPFCachePolicyCacheThenNetwork;

    }

    [query orderByAscending:@"name"];

    return query;
}

cellForRowAtIndexPath

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath object:(PFObject *)objects
{
    static NSString *simpleTableIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
    }

    //loading icons
    PFFile *thumbnail = [objects objectForKey:self.imageKey];
    PFImageView *thumbnailImageView = (PFImageView*)[cell viewWithTag:100];
    thumbnailImageView.file = thumbnail;
    thumbnailImageView.image = [UIImage imageNamed:@"placeholder.jpg"];


    [thumbnailImageView loadInBackground:^(UIImage *image, NSError *error) {
        if (!error) {

        }
    }];



    //cell
    cell.textLabel.text = [objects objectForKey:self.textKey];

    return cell;
}

提前致谢:)

【问题讨论】:

    标签: ios objective-c uitableview uiimageview parse-platform


    【解决方案1】:

    在短暂的延迟后加载图像并没有什么坏处。这是一个标准程序,许多世界级的应用程序都遵循这一程序(曾经尝试在 Facebook 或 Twitter 应用程序中滚动)。解决这个问题在逻辑和程序方面会非常混乱。

    【讨论】:

    • 也许这是真的,但是否可以让单元格在前 0.3 秒显示缓存中的图像?或者至少像其他应用一样创建一个加载屏幕?
    • 是的,这当然是可能的。您会想了解更多关于 UIActivityIndi​​catorView 及其用途的信息。
    • 好吧,但是更快地设置缓存是不可能的吧?那么在对象加载完成之前显示启动屏幕呢?
    • 我会说,在用户界面上让用户停留在启动屏幕上是一种不好的做法。而且我无法理解您所说的拆分缓存是什么意思。
    • 您还可以查看在内部进行缓存的 AsyncImageView。 github.com/nicklockwood/AsyncImageView 如果来自 parse 的图像有一个公共 URL,你可以让 AsyncImageView 加载它们,第一次加载会很慢,但缓存会自动完成。解析对象也应该被缓存:parse.com/questions/hascachedresult-always-returns-no "PFFiles 总是缓存到磁盘...你可以通过检查 PFFile 的 isDataAvailable 属性来检查 PFFile 是否已经缓存到磁盘。"
    【解决方案2】:

    我认为最好的方法是 facebook 在他们的应用程序上这样做。 Facebook 在图片所属的地方显示了一个空的灰色容器,一旦下载了图片,它们就会以动画方式淡入淡出。我认为这是要走的路的原因是因为加载图像然后在准备好后可能加载另一个图像似乎没有意义,最好只持有一个空容器并在准备好后加载图像。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-29
      • 2015-09-21
      • 1970-01-01
      • 2015-09-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多