ios - How to ensure remotely-fetched images in UITableView cells always filled? -
i have gotten question several times in job interviews: have uitableview , user scrolling fast. how make sure @ of cells' images being loaded server visible wherever user scrolls to.
i can think of several techniques. instance have done use operation queue, loaded requests fetch images, , when user starts scrolling, empty queue , fill requests images wherever user going towards.
another solution fill images super-low-resolution thumbnails e.g. 4-point gradient image, albeit bad one, there long before real image arrives.
i key here "wherever user scrolls to". because of that, shouldn't start downloading images until know cells going visible.
so watch uiscrollviewdelegate call:
- (void)scrollviewdidenddecelerating:(uiscrollview *)scrollview
at point, cells visible using:
- (nsarray *)indexpathsforvisiblerows
and spin off downloads images. putting together:
- (void)scrollviewdidenddecelerating:(uiscrollview *)scrollview { nsarray *theindexpaths = [self.tableview indexpathsforvisiblerows]; (nsindexpath *theindexpath in theindexpaths) { someobject *myobject = self.listofmyobjects[theindexpath.row]; [myobject downloadimage]; } }
this basic. need update cell, etc.
Comments
Post a Comment