我的表格视图中的第一个可见缩略图无法出现 - 使用 LazyTableImages 示例作为基础
我改编了developer.apple.com上的LazyTableImages示例中的代码,除了无法加载前4行的图像(加载时有4行可见)之外,它一切正常。当我向下滚动并停止时,新行的图像会正确加载,当我向上滚动时,前 4 个图像也会正确加载。所以问题是初始加载。
我使用 fetch 控制器加载表数据,它从 CoreData 数据库读取。在我的 cellForRowAtIndexPath 方法中,我添加了一个额外的检查,如下所示:
if (self.screeningsTable.dragging == NO &&
self.screeningsTable.decelerating == NO && movie.MovieID) {
[self startImageDownload:movie forIndexPath:indexPath];
}
检查该行是否确实具有有效的对象。因此,为了加载第一行的图像,我在从数据库加载数据后添加了 [self loadImagesForOnscreenRows]
,但它不起作用。
您能告诉我应该将 [self loadImagesForOnscreenRows]
放在哪里,以便正确加载第一个图像吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我发现了问题 - TableView reloadData 方法重新加载的速度不够快,因此当
[self loadImagesForOnscreenRows]
启动时,单元格还不存在。所以我用[myTable PerformSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:YES]; 替换了
[myTable reloadData];
,这成功了。希望对某人有帮助。
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.