表格单元格中图像视图的线程缩略图加载
我正在寻找有关如何为表格形式的导航列表制作高效缩略图加载器的建议。我可以启动一个线程并下载并缓存缩略图,但我不确定如何使用图像更新表格单元格(可见或视图之外的单元格)。
如果我没记错的话,我认为 Blocket 应用程序可以实现我想要的功能。
我想设置一个占位符图像,当线程加载每个图像时,它会更新单元格。如果可能的话,占位符可以是动画活动指示器(旋转器)。
是否有任何简洁的示例代码,或者您能否就如何将更新传达给单元格并强制其立即显示图像提供建议?
I'm looking for suggestions on how to make an efficient thumbnail-loader for navigation-lists in the form of tables. I can start a thread and download and cache the thumbnails, but I'm unsure on how to update a table cell with the image (a cell either visible or outside the view).
I think the app Blocket does what I'm after, if I remember correctly.
I'd like to set a placeholder image, and as the thread loads each image, it updates the cells. The placeholder could be an animated activity indicator (spinner), if possible.
Are there any terse example-code out there, or can you give suggestions on how to communicate the update to the cell and force it to display the image immediately?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
有趣的问题。
我想在某种程度上,您需要通过
reloadRowsAtIndexPaths:withRowAnimation:
UITableView 方法,所以我怀疑您需要查找单元格内容 -> indexPaths,以便您知道当相关资产可用时要更新哪些单元格。但是,您需要避免破坏现有的单元重复使用系统。 (即:提前预先创建所有单元格没有任何价值。)因此,大部分工作应该在 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath < 内完成我怀疑是 href="http://developer.apple.com/library/ios/#documentation/uikit/reference/UITableViewDelegate_Protocol/Reference/Reference.html" rel="nofollow">UITableViewDelegate 方法。
也就是说,希望您能得到比这些有些模糊的漫无目的更好的回应。 :-)
Interesting problem.
I guess at some level you'll need to replace the existing cells in the table view via the
reloadRowsAtIndexPaths:withRowAnimation:
UITableView method, so I suspect you'll need to keep a lookup of cell contents -> indexPaths so you know which cells to update when the relevant asset becomes available.However, you'll need to avoid breaking the existing cell re-use system. (i.e.: there's no value in pre-creating all of the cells in advance.) As such, much of this work should be done within the - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath UITableViewDelegate method, I suspect.
That said, hopefully you'll get a better response than these somewhat vague ramblings. :-)
制作了我在 iPhone 上见过的最好的线程缩略图加载:D 最难的部分是在离开线程表时取消线程。一个 NSThread 加载图像,并在更新 cell.imageView 时执行 waitUntilDone:YES,在数组中传递对象(cell、tableView、indexPath 等)以绕过 withObject 中仅传递一个对象的限制。每张图像加载时都会快速淡入,看起来很皇家:)
Made the nicest threaded thumbnail loading I've seen yet on iPhone :D The hardest part was cancelling a thread when navigating away from its table. An NSThread loading images and performSelectorOnMainThread waitUntilDone:YES for when updating the cell.imageView, passing objects (cell, tableView, indexPath etc) in an array to bypass the limitation of passing only one object in withObject. Looks royale with a quick fade-in of each image as they load :)