iphone - How to know when UIimageView finished loading? -


in view controller, how can know when uiimageview has finished loading (large jpeg documents directory)? need know can swap placeholder low-res imageview hi-res imageview. need create custom callback know this? way fine.

by way, here snippet of code load image:

nsstring *filename = [nsstring stringwithformat:@"hires_%i.jpg", currentpage]; nsstring *filepath = [nsstring stringwithformat:@"%@/bookimage/%@", [self documentsdirectory], filename]; hiresimageview.image = [[[uiimage alloc] initwithcontentsoffile:filepath] autorelease]; 

uiimageview isn't doing loading @ all. loading being done [[uiimage alloc] initwithcontentsoffile:filepath], , thread blocked while file loaded (so load complete time call returns).

what want this:

- (void)loadimage:(nsstring *)filepath {     [self performselectorinbackground:@selector(loadimageinbackground:) withobject:filepath]; }  - (void)loadimageinbackground:(nsstring *)filepath {     nsautoreleasepool *pool = [[nsautoreleasepool alloc] init];     uiimage *image = [[uiimage alloc] initwithcontentsoffile:filepath];     [self performselectoronmainthread:@selector(didloadimageinbackground:) withobject:image waituntildone:yes];     [image release];     [pool release]; }  - (void)didloadimageinbackground:(uiimage *)image {     self.imageview.image = image; } 

you set self.imageview display low-res image , call loadimage: load high-res version.

note if call repeatedly before didloadimageinbackground: gets called earlier calls, may cause device run out of memory. or might have image first call take longer load image second call didloadimageinbackground: gets called second image before gets called first. fixing issues left exercise reader (or question).


Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -