Best practices for downloading images in a UITableView's cells? iOS/Swift -
so had argument @ work what's better downloading images in uitableview's cells.
the 2 options are: in cellforrowatindex, download image asynchronously leads using multiple threads , multiple network requests suspect may issue battery drain.
the other option download images @ once using 1 thread , 1 network request, looping through array images' urls outside cellforrowatindex of coarse, , calling the table view reload function.
there slight modification latter approach can set each image (perhaps calling reload function) each image downloaded.
so love know, what's industry standard way of handling this? pros , cons when comes performance? there better ways?
i use sdwebimage, caches images , can reused later. provides flexibility extensions , various methods.
check implemented code:
import uikit import sdwebimage extension acceptedwinksviewcontroller: uitableviewdatasource { func tableview(_ tableview: uitableview, cellforrowat indexpath: indexpath) -> uitableviewcell { let cell = tableview.dequeuereusablecell(withidentifier: constants.cellidentifier.winklisttableviewcell) as! winklisttableviewcell let profile = self.winklist[indexpath.row] //model let placeholderimage = uiimage(named:"placeholder") //your placeholder image, can class or global variable if let url = profile.imageurl { cell.userimageview.sd_setimage(with: url, placeholderimage: placeholderimage, options: .refreshcached, completed: nil) //check various options } else { cell.userimageview.image = placeholderimage } return cell } }
Comments
Post a Comment