2012-08-09 17 views
2

我希望在通过NSURL字符串上传期间使用MBProgressHUD显示消息。所以我编码:如何使用两个后续的MBProgressHUD消息

MBProgressHUD *hud1 = [MBProgressHUD showHUDAddedTo:self.view animated:YES]; 
hud1.labelText = @"sending info ..."; 
hud1.minShowTime =10.0; 

NSURL *url =[NSURL URLWithString:self.urlToUpload]; 

10秒钟是为了等待一段时间我想用户等待。它有效,但当第一个消失时我会显示另一条消息。使用另一个:

MBProgressHUD *hud2 = [MBProgressHUD showHUDAddedTo:self.view animated:YES]; 
hud2.labelText = @"SENT!"; 
hud2.minShowTime =2.0; 

它没有用,因为此消息与第一个重叠。 关于这方面的任何提示?

回答

6

我会删除您的-connectionDidFinishLoading方法中的第一个HUD,或者通知您字符串已成功上传的任何地方。

[MBProgressHUD hideHUDForView:self.view animated:YES]; 

然后你可以添加你的下一个HUD 1-2秒。通过在特定时间添加它,在下一个显示之前无法准确移除第一个HUD。

这是取自MBProgressHUD演示项目。我会用它来显示你的定时完成HUD。

HUD = [[MBProgressHUD alloc] initWithView:self.navigationController.view]; 
[self.navigationController.view addSubview:HUD]; 

// The sample image is based on the work by http://www.pixelpressicons.com, http://creativecommons.org/licenses/by/2.5/ca/ 
// 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:@"37x-Checkmark.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提供的成功消息。 – Aashish 2018-01-31 07:46:47

0
+(void)toast:(NSString*) str view:(UIView*)view delegate:(id)delegate type:(IconType)type{ 

    [MBProgressHUD hideHUDForView:view animated:YES]; 

    MBProgressHUD * HUD = [[MBProgressHUD alloc] initWithView:view]; 
    [view addSubview:HUD]; 

    NSString* strImage; 
    switch (type) { 
     case kNone: 
      strImage=nil; 
      break; 
     case kOK: 
      [email protected]"37x-Checkmark.png";//NSString stringWithFormat:@"%@", 
      break; 
     case kError: 
      [email protected]"ic_cancel_white_24dp.png";//NSString stringWithFormat:@"%@", 
      break; 
     default: 
      break; 
    } 

    HUD.customView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:strImage] ]; 

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

    HUD.delegate = delegate; 
    HUD.labelText = str; 
    HUD.userInteractionEnabled = NO; 

    [HUD show:YES]; 
    [HUD hide:YES afterDelay:1.5f]; 
} 
相关问题