Search code examples
iosswiftuiimageviewuicollectionviewsdwebimage

Loading images from Paths using SDWebImage for UICollectionView Reusable Cells - Swift


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 :)


Solution

  • 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