How to implement UIImageView-like delayed loading in UITableView
Background: I have a UITableView showing an image in each cell. These images are all part of a big pdf-file. So what I am doing is actually rendering little pdf-parts in those UITableViewCells, eac开发者_如何学运维h cell displaying just one piece. Therefore I add a UIView to the contentview of the cell and render the view on demand. Rendering these pdf-parts is expensive and each takes about 0.2 seconds (only drawing the Pdf-part), which slows the scrolling of the table terrible down.
Idea: Now, I know there may be a solution when I look how UIImage renders URL-based images. If you create a UIImage based on a url, these images are rendered somehow delayed. E.g have a look at the iTunes-App. Smooth scrolling is possible, each image is displayed unrendered and after rendering is finished it appears smoothly.
Problem: How can I render an expensive rendering in a UITableViewCell like described above, by somehow showing the cell delayed? Has anybody an idea, how Apple solved it within UIImageView?
Thanks in advance
Daniel
this is (mostly) duplicate of Lazy load images in UITableViewCell. Check the links and examples there.
In short, what you need is spawning a separate thread for loading the PDF thumbnails, and that thread then signaling back to the main thread with the generated images. This is easily done by using performSelectorInBackground:withObject:
and performSelectorOnMainThread:withObject:waitUntilDone:
methods.
精彩评论