.h
#import <UIKit/UIKit.h> #import "MBProgressHUD.h" @interface ViewController : UIViewController<MBProgressHUDDelegate> { MBProgressHUD *HUD; } -(IBAction)showWithLable:(id)sender; -(void)myTask; @end
.m
// // ViewController.m // MBprogressbarTest // // Created by jstv.com jstv on 12-6-10. // Copyright (c) 2012年 jstv.com. All rights reserved. // #import "ViewController.h" @interface ViewController () @end @implementation ViewController -(void)myTask { sleep(3); } -(void)hudWasHidden { [HUD removeFromSuperview]; [HUD release]; } -(IBAction)showWithLable:(id)sender { HUD = [[MBProgressHUD alloc] initWithWindow:[UIApplication sharedApplication].keyWindow]; [self.view.window addSubview:HUD]; HUD.delegate = self; HUD.labelText = @"loading..."; [HUD showWhileExecuting:@selector(myTask) onTarget:self withObject:nil animated:YES]; } - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. } - (void)viewDidUnload { [super viewDidUnload]; // Release any retained subviews of the main view. } - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown); } @end