@implementation HudDemoViewController
-
( IBAction )
showWithLabel:( id )sender
{
//
Should be initialized with the windows frame so the HUD disables all user input by covering the entire screen
HUD
= [[MBProgressHUD alloc] initWithWindow:[UIApplication sharedApplication].keyWindow];
//
Add HUD to screen
[ self .view.window
addSubview:HUD];
//
Regisete for HUD callbacks so we can remove it from the window at the right time
HUD.delegate
= self ;
HUD.labelText
= @ "Loading" ;
//
Show the HUD while the provided method executes in a new thread
[HUD
showWhileExecuting: @selector (myTask)
onTarget: self withObject: nil animated: YES ];
}
-
( void )
myTask {
//
Do something usefull in here instead of sleeping ...
sleep(3);
}
-
( void )hudWasHidden
{
//
Remove HUD from screen when the HUD was hidded
[HUD
removeFromSuperview];
[HUD
release];
}
@end
原文:http://www.cnblogs.com/GnagWang/archive/2011/09/29/2195710.html
|