我想在通过NSURL字符串上传期间使用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;
它没用,因为这条消息与第一条消息重叠。 有关于此的任何提示吗?
答案 0 :(得分:6)
我会删除您-connectionDidFinishLoading
方法中的第一个HUD,或者在您收到有关该字符串已成功上传的通知的任何位置。
[MBProgressHUD hideHUDForView:self.view animated:YES];
然后你可以添加你的下一个HUD 1-2秒。只需在特定时间添加它,就无法在下一个HUD显示之前准确删除第一个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];
答案 1 :(得分: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:
strImage=@"37x-Checkmark.png";//NSString stringWithFormat:@"%@",
break;
case kError:
strImage=@"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];
}