PerformSelector:withObject:afterDelay 未针对 MBProgressHUD 执行

发布于 2024-12-26 14:26:53 字数 696 浏览 2 评论 0原文

我对 MBProgressHUD 有以下方法:

 [progressHUD performSelector:@selector(hide:) 
                   withObject:[NSNumber numberWithBool:YES] 
                   afterDelay:kMessageHidingDelay];

此处的延迟为 2.0,但在 2.0 秒后不会调用 hide。我试图在隐藏函数中放置一个断点,但它没有到达那里。有什么想法吗?这是完整的代码:

progressHUD = [[MBProgressHUD alloc] initWithView:viewToAttach];

            // Add HUD to screen
            [viewToAttach addSubview:progressHUD];
            progressHUD.labelText = @"Logging In";
            progressHUD.removeFromSuperViewOnHide = YES;
            // Show the HUD while the provided method executes in a new thread

            [progressHUD show:YES];

I have the following method for a MBProgressHUD:

 [progressHUD performSelector:@selector(hide:) 
                   withObject:[NSNumber numberWithBool:YES] 
                   afterDelay:kMessageHidingDelay];

the delay is 2.0 here, however it's not calling hide after 2.0 seconds. I tried to put a breakpoint in the hide function and it's not getting there. Any idea? Here's the full code:

progressHUD = [[MBProgressHUD alloc] initWithView:viewToAttach];

            // Add HUD to screen
            [viewToAttach addSubview:progressHUD];
            progressHUD.labelText = @"Logging In";
            progressHUD.removeFromSuperViewOnHide = YES;
            // Show the HUD while the provided method executes in a new thread

            [progressHUD show:YES];

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

从此见与不见 2025-01-02 14:26:53

可能会尝试在主线程上执行选择器(所有 UI 更改都必须在主线程上完成)?
performSelectorOnMainThread:

May be try to perform selector on Main thread (all UI changes must be done on main thread)?
performSelectorOnMainThread:

蓝海似她心 2025-01-02 14:26:53

你必须隐藏 MBProgressHud

[progressHUD hide:YES];

you have to hide the MBProgressHud

[progressHUD hide:YES];
独自←快乐 2025-01-02 14:26:53

要显示 MBProgressHUD,请使用此代码:-

  HUD = [[MBProgressHUD alloc] init];

  [self.view addSubview:HUD];

  HUD.delegate = self;

  [HUD showWhileExecuting:@selector(myTask) onTarget:self withObject:nil animated:YES];

  where myTask is

   - (void)myTask 
  {
     "Your Code"
  }

并且隐藏 MBProgressHud

 - (void)hudWasHidden:(MBProgressHUD *)hud
    {
       // Remove HUD from screen when the HUD was hidded
       [HUD removeFromSuperview];
       [HUD release];
   HUD = nil;
   }

,如果您想在 CostomView 中显示 Hud,请使用此代码

   HUD = [[MBProgressHUD alloc] init];

[self.view addSubview:HUD];

// Make the customViews 37 by 37 pixels for best results (those are the bounds of the build-in progress indicators)
HUD.customView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Your Image Name.png"]] autorelease];

// Set custom view mode
HUD.mode = MBProgressHUDModeCustomView;

HUD.delegate = self;

HUD.labelText = @"Completed";

[HUD show:YES];

[HUD hide:YES afterDelay:3];

}

To Show MBProgressHUD Use this Code:-

  HUD = [[MBProgressHUD alloc] init];

  [self.view addSubview:HUD];

  HUD.delegate = self;

  [HUD showWhileExecuting:@selector(myTask) onTarget:self withObject:nil animated:YES];

  where myTask is

   - (void)myTask 
  {
     "Your Code"
  }

And too Hide the MBProgressHud

 - (void)hudWasHidden:(MBProgressHUD *)hud
    {
       // Remove HUD from screen when the HUD was hidded
       [HUD removeFromSuperview];
       [HUD release];
   HUD = nil;
   }

And If you Want to Show Hud With Your CostomView Then Use This Code

   HUD = [[MBProgressHUD alloc] init];

[self.view addSubview:HUD];

// Make the customViews 37 by 37 pixels for best results (those are the bounds of the build-in progress indicators)
HUD.customView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Your Image Name.png"]] autorelease];

// Set custom view mode
HUD.mode = MBProgressHUDModeCustomView;

HUD.delegate = self;

HUD.labelText = @"Completed";

[HUD show:YES];

[HUD hide:YES afterDelay:3];

}

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文