iphone - How to put placeholder image and redraw cell when image is downloading from URL? -


i'm trying put placeholder images in table view cell. there event trigger redraw of cell contents once image data uploaded? i'm using following create image:

[uiimage imagewithdata:[nsdata datawithcontentsofurl:[nsurl urlwithstring:photourlstring]]]  

side note: i'm using abtableviewcell manually draw contents of cell drawinrect method.

thanks.

that call synchronous, when complete image ready.

what want loading image asynchronously , updating image loaded.

something like:

nsurl *url = [nsurl urlwithstring:imageurl]; nsurlrequest *request = [nsurlrequest requestwithurl:url]; nsurlconnection *conn = [[nsurlconnection alloc] initwithrequest:request delegate:self]; 

set property contain nsdata , keep track of nsurlconnection can release it.

self.activedownload = [nsmutabledata data]; self.imageconnection = conn; 

then provide proper delegate methods handling connection callbacks:

- (void)connection:(nsurlconnection *)connection didreceivedata:(nsdata *)data {    [self.activedownload appenddata:data]; }  - (void)connection:(nsurlconnection *)connection didfailwitherror:(nserror *)error {   // clear activedownload property allow later attempts   self.activedownload = nil;    // release connection it's finished   self.imageconnection = nil; }  - (void)connectiondidfinishloading:(nsurlconnection *)connection {   // set appicon , clear temporary data/image   uiimage *image = [[uiimage alloc] initwithdata:self.activedownload];    //make callbacks , update image here. } 

your callback going want obtain image, , set in such way reload of table view able retrieve properly. i.e. set image in data object rest of data table view cell uses.

additionally, can single refresh of cell needs via:

- (void)reloadrowsatindexpaths:(nsarray *)indexpaths withrowanimation:(uitableviewrowanimation)animation 

this apple's own lazyimagetables example.


Comments

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -