i have scrollview add uibuttons , uiactivityindicators in main thread. perform [nsthread detachselectorinbackground:@selector(getimages) totarget:self withobject:nil];
getimages downloads images , add them uiimageviews , adds uiimageviews scrollview, wont show until method getimages done. there way scrollview redraw or refresh or that?
and if scroll scrollview (with fingers..) during getimages method, uiimageviews has been added shows up.
- (void) getimages { nsautoreleasepool *pool = [[nsautoreleasepool alloc] init]; int x=5; int y=0; nsdata *imgdata; uiimage *img; uiimageview *imgview; (nsdictionary *tmp in thumbs) { imgdata = [[nsdata alloc] initwithcontentsofurl:[nsurl urlwithstring:[functions urlforfile:[tmp objectforkey:@"img"]]]]; if ([imgdata length] > 0) { img = [[uiimage alloc] initwithdata:imgdata]; imgview = [[uiimageview alloc] initwithframe:cgrectmake(x, y + (133-img.size.height)/2, 100, img.size.height)]; imgview.image = img; [imgview setalpha:0.0]; [[self.scrollview viewwithtag:1500000*[[tmp objectforkey:@"id"] intvalue]] setalpha:1.0]; [self.scrollview addsubview:imgview]; [uiview beginanimations:nil context:null]; [uiview setanimationbeginsfromcurrentstate:yes]; [uiview setanimationduration:2.0]; [[self.scrollview viewwithtag:1500000*[[tmp objectforkey:@"id"] intvalue]] setalpha:0.0]; [imgview setalpha:1.0]; [uiview commitanimations]; [[self.scrollview viewwithtag:1500000*[[tmp objectforkey:@"id"] intvalue]] removefromsuperview]; [imgview release]; [img release]; [imgdata release]; x+=105; if (x > 300) { x=5; y+=138; } } } [pool release]; [appdelegate.loadingview sethidden:yes]; }
changing ui in background not thread-safe! downloading in background not displaying. show image 1 one can try run performselectoronmainthread:@selector() withobject:nil waituntildone:yes
example self.scrollview addsubview:
.
but again, ui should use mainthread (e.g. animations)
Comments
Post a Comment