HUD that uses Mbprogresshud can't be displayed immediately.

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.