2012-01-10 57 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]; 
相關問題