0

Unlike a data source object which provides data on-demand, the UICollectionView Layout is a delegate that layout the whole collection view once. (calling sizeForItemAtIndexPath for all items).

My question is, if I have a collection view of 100 items, each item consists a image from a URL, and I want to display the images with their aspect ratio. When should I make URL request and get the images ?

Note: In order for the layout to work, I have to make 100 URL requests to get all the images, and figure out their sizes; but the UI only needs to show a few at a time (cellForItemAtIndexPath)

Note: Could the UICollectionView asks for the sizeForItem On Demand (like a data source) ?

Note: UITableView has an "estimatedHeight" and "Height", why and when will Collection View has them ?

Andy
  • 31
  • 3
  • There are lots of tutorials explaining how to supply a table/collection view with images downloaded as needed. – matt Feb 13 '14 at 00:07
  • Thanks Matt. Do you have any example ? Most tutorial use the fixed cell size, but if we want to preserve the aspect ratio, we need to get the image first then figure out the size. – Andy Feb 13 '14 at 00:22
  • That's impossible unless you expect to travel backwards in time. You have to display *something* while you are waiting for the image. You can always adjust the layout after the image arrives... – matt Feb 13 '14 at 00:59

0 Answers0