HUD that uses Mbprogresshud can't be displayed immediately.
problem encountered:
With Mbprogresshud, if you add a HUD to a function, and you do a time-consuming operation before the end of the function, the HUD doesn't show up right away, it needs to wait until the end of the function to show it, as in the following example, until the For loop is finished.
-(Ibaction) Showtextonly: (ID) Sender {
Mbprogresshud *hud = [Mbprogresshud showhudaddedto: Self.navigationController.view Animated:yes];
Hud.mode = Mbprogresshudmodetext;
Hud.labeltext = @ "Some message ...";
Hud.margin = 10.F;
Hud.removefromsuperviewonhide = YES;
for (int i=0; i<5; i++) {sleep
(1);
}
}
Reason:
Uikit cannot be repaint before the end of the current run loop, that is, you need to repaint and update the UI in the next run loop cycle. Solution:
The following method runs your time-consuming program and then hides the HUD at the end of the MYTADK
Setup and show HUD here
[self performselector: @selector (mytask) Withobject:nil afterdelay:0.001];
Or you can run the run loop manually
Setup and show HUD here
[[[Nsrunloop Currentrunloop] rununtildate:[nsdate Distantpast]];
Insert MyTask code here
//Hide the shown HUD here
or use blocks
Dispatch_after (Dispatch_time (dispatch_time_now, 0.001 * nsec_per_sec), Dispatch_get_main_queue (), ^ (void) {
// Insert mytask code here
});
Reference
Refer to discussion from stack overflow