0

次のコードは、サンプル デモからのものです。

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

HUD.delegate = self;
HUD.labelText = @"Loading";

[HUD showWhileExecuting:@selector(myTask) onTarget:self withObject:nil animated:YES];

ビューとして .xibs を使用します。ストーリーボードを使用するアプリケーションを作成しています。したがって、HUD をインスタンス化するときの initWithView メソッド用の navigationController はありません。.xibs と navigationController を使用せずに HUD を実装する方法はありますか? 「self」と「self.view」の両方を渡そうとしましたが、うまくいきません。これが入っているクラスは ViewController.m クラスであり、UIViewController クラスです。だから、なぜ自分自身を渡すことがうまくいかないのかわかりません。

これは私のコードです

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

繰り返しますが、「自己」は私のメインViewControllerです

ありがとう!

4

1 に答える 1

1

ここにあなたが欲しいと思うものがあります:

MBProgressHUD *hud = [[MBProgressHUD alloc] initWithView:view];
[view addSubview:hud];    
[hud showWhileExecuting:@selector(YOUR_TASK) onTarget:YOUR_TARGET withObject:nil animated:YES];  // or NO if you don't want it to be animated

別の方法として、HUD の表示と表示を手動で管理したい場合は、それを行うための便利な方法がいくつかあります。

// To add HUD to a view
MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];  // or NO if you don't want it to be animated

// To set HUD text
[hud setLabelText:@"Text"];

// To remove HUD from a view (such as later in the code, after load, etc)
[MBProgressHUD hideHUDForView:view animated:YES];

viewHUD を追加/削除するビューはどこにありますか。

つまり self.view、View Controller上です。

于 2013-08-13T20:47:10.853 に答える