1

i edited the question to be more specific: i need to accomplish a UICollectionView with multiple reusable collection cells each having a UIImage loaded from a path using SDWebImage. i want all the images to load and THEN show all of them inside the collection view at once. my problem is: when i use sd_setImageWithURL inside the function:

func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell

the images do not load. im trying to reload the collection's data everywhere - but it doesn't load them.

what is the proper way to SDWebImage to load the images to the collection view and make them appear?

Thank you in advance to all those who take the time to read and help :)

MarkosDarkin
  • 315
  • 3
  • 20
  • Your question is quite broad, but essentially you need to kick off the download of all the images and once they have all been downloaded, then put the appropriate data into the array that drives your collectionview and reload the collection view. You can use a dispatch_group and a dispatch_group_notify to load the collection view once everything is done – Paulw11 Aug 15 '16 at 10:45
  • Thank you Paulw11 for the quick reply :) ill try it now – MarkosDarkin Aug 15 '16 at 10:47

1 Answers1

1

Read this:

  1. Swift: load images Async in UITableViewCell
  2. Best way to load image url swift 2 in UITableView
  3. how to implement lazy loading of images in table view using swift

Main idea of loading images in tableview:

  1. generate images urls/paths array
  2. start loading images in utility thread (GCD)
  3. fill tableView with cell without images
  4. update cells (uitableView.visibleCells) in main thread when you get event*

*usual event types:

  1. when one image or all images are loaded
  2. UITableViewDelegate protocol events (https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITableViewDelegate_Protocol/)
  3. touch event
  4. transition event
Community
  • 1
  • 1
Vasily Bodnarchuk
  • 24,482
  • 9
  • 132
  • 127