开发者

The first visible thumbnails in my tableview fail to appear - using LazyTableImages example as a base

I adapted the code from the LazyTableImages example on developer.apple.com and it all works except that it failed to load the images for the first 4 rows (there are 4 rows visible on load). When I scroll down and stop, the new rows' images are loaded correctly and when I scroll back up, the fist 4 images are also loaded correctly. So the problem is the initial loading.

I use fetch controller for loading the table data and it reads from a CoreData database. In my cellForRowAtIndexPath method I added an additional check like this:

if (self.screeningsTable.dragging == NO &开发者_开发技巧& 
    self.screeningsTable.decelerating == NO && movie.MovieID) {
  [self startImageDownload:movie forIndexPath:indexPath];
}

as to check if the row actually has a valid object yet. So in order to load the images of the first rows, I added [self loadImagesForOnscreenRows] after the data has been loaded from the database, but it doesn't work.

Can you tell where I should put the [self loadImagesForOnscreenRows] so the first images are correctly loaded?


I found the problem - the TableView reloadData method didn't reload fast enough, so when the [self loadImagesForOnscreenRows] started, the cells weren't there yet. So I replaced [myTable reloadData]; with [myTable performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:YES]; which did the trick. Hope that helps someone.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜