performSelector:withObject:afterDelay不为MBProgressHUD执行

时间:2012-01-10 21:34:42

标签: iphone objective-c ios ipad mbprogresshud

我对MBProgressHUD有以下方法:

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

这里的延迟是2.0,但是它在2.0秒后没有调用hide。我试图在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];

3 个答案:

答案 0 :(得分:0)

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

答案 1 :(得分:0)

显示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];

}

答案 2 :(得分:0)

你必须隐藏MBProgressHud

[progressHUD hide:YES];