zoukankan      html  css  js  c++  java
  • MBProgressHUD not showing

    In my app, I am loading a resource heavy view that takes about 1 to 2 seconds to load. So I am loading it in a separate thread like this:

    hud = [[MBProgressHUD alloc] init];
    [hud showWhileExecuting:@selector(loadWorkbench:) onTarget:self withObject:nil animated:YES];

    however it never appears, and application looks frozen to the end user. any ideas where I have gone wrong?

    Yes. It does not appear because you never tell add the HUD as a subview of the window. try something like:

        // Should be initialized with the windows frame so the HUD disables all user input by covering the entire screen
        HUD = [[MBProgressHUD alloc] initWithWindow:[UIApplication sharedApplication].keyWindow];
    
        // Add HUD to screen
        [self.view.window addSubview:HUD];
    
        // Register for HUD callbacks so we can remove it from the window at the right time
        HUD.delegate = self;
    
        HUD.labelText = NSLocalizedString(@"Loading Workbench", nil);
        HUD.detailsLabelText = NSLocalizedString(@"please wait", nil);
    
        // Show the HUD while the provided method executes in a new thread
        [HUD showWhileExecuting:@selector(loadWorkbench:) onTarget:self withObject:nil animated:YES];

    Since you are setting yourself as the HUD delegate, also add the following delegate method:

    - (void)hudWasHidden {
        // Remove HUD from screen 
        [HUD removeFromSuperview];
    
        // add here the code you may need
    
    }

    and remember to add MBProgressHUDDelegate in the corresponding header file.

  • 相关阅读:
    如何在iTerm2中配置oh my zsh?
    sublime中格式化jsx文件
    ES6 new syntax of Literal
    ES6 new syntax of Rest and Spread Operators
    How to preview html file in our browser at sublime text?
    ES6 new syntax of Default Function Parameters
    ES6 new syntax of Arrow Function
    七牛云2018春招笔试题
    Spring-使用注解开发(十二)
    Spring-声明式事物(十一)
  • 原文地址:https://www.cnblogs.com/ghgyj/p/4056119.html
Copyright © 2011-2022 走看看