出力は次のようになります。
まず、ここから MBProgressHUD.h と MBProgressHUD.m をインポートします。
次に、ViewController.h に次のコードを記述します。
#import <UIKit/UIKit.h>
#import "MBProgressHUD.h"
@interface ViewController : UIViewController
{
MBProgressHUD *HUD;
}
次に、ViewController.m に次のメソッドを記述します。
//To Add Loading View on current View
- (void)showOnWindow {
// The hud will disable all input on the view
HUD = [[MBProgressHUD alloc] initWithView:self.view.window];
// Add HUD to screen
[self.view addSubview:HUD];
// Register for HUD callbacks so we can remove it from the window at the right time
HUD.labelText = @"Loading...";
// Show the HUD while the provided method executes in a new thread
[HUD showWhileExecuting:@selector(yourtask) onTarget:self withObject:nil animated:YES];
}
それで、
// To Remove the Loading View from current view
- (void)removeOnWindow {
// Do something useful in here instead of sleeping ...
[HUD removeFromSuperview];
}
次に、メソッド onClick イベントを呼び出します....
// Add Loading View
- (IBAction)SetSignIn:(id)sender {
[self showOnWindow];
}
// yourtask method
-(void)yourtask {
@try{
// Do Whatever you want
// You can call webservices also
}
@catch (NSException *e) {
NSLog(@"Error");
}
@finally{
[self removeOnWindow];
}
}