2014-10-28 84 views
0

一切工作正常,除了在一个令人不安的延迟后,单元格中的图像显示出来。在tableView完成加载后大约0.3秒。我认为很短的时间内显示一个空白图像是非常丑陋的...在UITableVIew加载之前从解析中检索图像?

如何才能让tableView在刚刚加载parse的图像后显示(为什么不从缓存中首先?)。或者我可以让启动屏幕保持更长时间..? 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; 
} 

感谢提前:)

回答

1

有一个短暂的延迟后加载图像没有坏处。这是一个标准程序,随后是许多世界级应用程序(曾尝试在Facebook或Twitter应用程序中滚动)。从逻辑和程序的角度来看,解决这个问题的工作会非常麻烦。

+0

也许这是真的,但有可能使单元格从缓存中显示图像的第0,3秒?或者至少创建一个像其他应用程序的加载屏幕? – Tibbe 2014-10-28 14:20:26

+0

是的,它肯定是可能的。你会想知道更多关于UIActivityIndi​​catorView及其用法。 – 2014-10-28 14:21:56

+0

好吧,但更快地设置缓存是不可能的吧?显示启动屏幕直到对象完成加载为止呢? – Tibbe 2014-10-28 14:24:28

1

我认为做这件事的最好方法就是facebook在他们的应用程序上执行此操作的方式。 Facebook在图像所属的位置显示一个空的灰色容器,一旦图像被下载,它们就会以动画的方式淡入。我认为这是一条路要走的原因是因为在准备好加载图像并准备好加载另一个图像似乎没有意义,最好是只需容纳一个空容器并准备好加载图像。