Empty scroll view and loading photos asynchronously
How can I init an empty scroll view with a certain number of pages (depending of number of photos I need to show), while an NSOperationQueue is downloading photos one by one from a web service ?
I would like to show an UIActivityIndicatorView on each page of the scroll view, and when one of开发者_高级运维 my photo is downloaded, show it on the corresponding page.
It seems there is no example on the Web...
The following 3 WWDC videos will help.
Session 105 - Polishing Your App WWDC 2011 Session 125 - UITableView Changes, Tips, Tricks WWDC 2011 UITableView Talk (don't recall the # or title) from WWDC 2010
Your question has no easy answer. But the general approach;
- create and init the scrollview as if you had the photos (i.e. set its contentSize to match the eventual photo count)
- download the photos in the background as you suggest
- as the photos come in use performSelector:onMainThread: method variants to send a message to one of your controllers on the main thread that an image is ready for display
- add a UIImageView to the correct page in the scroll view (WWDC 2010 Scroll View talk will help here)
good luck
精彩评论