objective-c - MBProgressHUD 不会显示

标签 objective-c ios mbprogresshud

我正在玩弄 MBProgressHUD。 viewcontroller(tableview)中的工作流程是这样的:

1) IBAction 被调用以在 2 个不同的表之间切换 2.1) 函数 reloadAllMonth 被调用(用新表的数据初始化一个数组) 2.2) MBProgressHUD *应该显示HUD 3)reloadAllMonth完成 4) HUD应该消失

我当前的代码:

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{

        //sparing you the code that determins where the tap occured

        HUD = [[MBProgressHUD alloc]initWithFrame:self.view.frame];
        [MBProgressHUD showHUDAddedTo:self.view animated:YES];
        [self reloadAllMonth];
        allMonthIsActive = YES;
        [MBProgressHUD hideHUDForView:self.view animated:YES];

// some other code table reload etc.
}

发生了什么:

-> 函数 touchesbegan 被调用 -> 3-4 秒内没有任何反应(加载时间) -> 弹出新表

问题:为什么 HUD 不显示?我哪里出错了?

最佳答案

你不能在同一个线程中同时显示和隐藏,这就是我要做的:

-(void)reloadStuff
{
    [self reloadAllMonth];
    allMonthIsActive = YES;
    [MBProgressHUD hideHUDForView:self.view animated:YES];
    isLoading = NO;
}

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    //sparing you the code that determins where the tap occured

    if (isLoading)
        return;
    isLoading = YES;
    [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    [self performSelectorInBackground:@selector(doStuff) withObject:nil];
}

您也可以删除 ivar HUD,您没有使用它。

并且不要忘记将 viewDidLoad 中的 isLoading 初始化为 NO:

isLoading = NO;

祝你好运!

关于objective-c - MBProgressHUD 不会显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9852288/

相关文章:

ios - 减小 iPhone 模拟器窗口的大小?

ios - WebdriverAgent : linker command failed with exit code 1 (use -v to see invocation)

ios - MBProgressHUD 在 iOS 中有时不显示

objective-c - Linux 上使用 Cocoa 的 Objective-C 的 Makefile 错误

ios - 在自定义单元格中设置自定义附件类型

ios - 如何释放在另一个函数中创建的对象?

ios - 如何在加载 UIwebview 时集成 MBProgressHUD?

objective-c - MacOS MTKView metal self.device.newBufferWithBytes 因断言而崩溃

iphone - UIVideoEditorController 丢失视频分辨率

ios - 将 MBProgressHUD 定位在屏幕的底部/顶部