2012-01-10 28 views
1

我有一个MBProgressHUD下面的方法:performSelector:withObject:afterDelay不执行对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]; 
+0

你为什么不使用: - (无效)隐藏:(BOOL)动画afterDelay:(NSTimeInterval)延迟; ? – Alin 2012-01-10 21:40:44

+0

我没有MBProgressHUD中的那个函数...我认为这是我的代码中的一个问题,并且与线程有关,因为当HUD旋转时,我正在做一些事情,什么时候简化了,这是否完美地工作。任何想法为什么? – adit 2012-01-10 21:54:59

+0

也许这是您MBProgressHUD版本中的错误。从这里获取最新的源代码:https://github.com/jdg/MBProgressHUD并尝试它。另外,请确保不要从非UI线程调用UI方法!如果你从另一个线程调用你的延迟方法,那就是你的问题。 – Alin 2012-01-10 22:05:20

回答

0

可能是尝试对主线程选择(所有UI变动,必须在主线程来完成)? performSelectorOnMainThread:

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 = [[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]; 

}

0

你要隐藏的MBProgressHud

[progressHUD hide:YES]; 
相关问题