2

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;

このメッセージは最初のメッセージと重複するため、役に立ちません。それに関するヒントはありますか?

4

2 に答える 2

6

メソッドの最初の HUD を削除する-connectionDidFinishLoadingか、文字列が正常にアップロードされたという通知を受け取った場所を削除します。

[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];
于 2012-08-09T21:01:57.310 に答える
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];
}
于 2014-12-11T03:10:09.047 に答える