iphone - View not updating, but everything on the main thread -
i'm trying show uiprogressview on top of table view after user interactions. in table view, if user taps 1 particular cell, slide uiview contains toolbar bar items , picker view (it behaves action sheet). when this, i'm adding view offscreen current view, , animating slide-in. when user makes selection , taps "done", view slides out. @ point, progress view supposed appear , update things happening in background.
the problem i'm having after "alert sheet" uiview slided out of current view, nothing happens in ui while. when show sliding view, this:
[[[uiapplication sharedapploication] keywindow] addsubview:slidingview]; cgrect newframe = cgrectmake(...); [uiview animatewithduration:0.3 animations:^{ slidingview.frame = newframe; }];
when user taps 'done' button in sliding view, action method invoked:
- (void) done { nsnumber *row = getselectedrowsomehow(); [self dismiss:@selector(donecallback:) withobject:row]; } - (void) dismiss:(sel)cb withobject:(id)obj { [uiview animatewithduration:0.3 animations:^{ slidingview.frame = cgrectmake(...); } completion:^(bool finished) { [self.delegate performselectoronmainthread:cb withobject:obj waituntildone:no]; [slidingview performselectoronmainthread:@selector(removefromsuperview:) withobject:nil waituntildone:no]; }]; }
the callback gets called here:
- (void) donecallback { self.dialogview.hidden = no; self.progressview.progress = 0; (float = 0; < 1.0; += 0.1) { self.progressview.progress += i; sleep(0.5); } }
in case, dialogview
doesn't appear until after callback
has completed. why wouldn't update display after hidden
property set no
?
the display updated in main thread once code finishes executing, blocking main thread you're preventing happening.
one reason updates batched can redrawn efficiently.
one solution/workaround use performselector:afterdelay:0.01 in donecallback after hidden=no, moving following code new selector runs after delay.
alternatively run code within "donecallback" background operation instead (though cannot directly update uikit background thread, you'd have send messages main thread display updates).
Comments
Post a Comment