MBProgressHud与故事板

时间:2013-08-13 20:44:11

标签: objective-c ios6 mbprogresshud

以下代码来自示例演示。

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。我试过通过“自我”和“自我查看”,但他们不起作用。它所在的类是ViewController.m类,它是一个UIViewController类。所以我不明白为什么传递自我是行不通的。

这是我的代码

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

再次,“self”是我的主要ViewController

谢谢!

1 个答案:

答案 0 :(得分: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];

view是您希望添加/删除HUD的视图。

即。 <{1}}在视图控制器上。