You will get the Output as :
Firstly import MBProgressHUD.h and MBProgressHUD.m from here
Then write the following code in ViewController.h
#import <UIKit/UIKit.h>
#import "MBProgressHUD.h"
@interface ViewController : UIViewController
{
MBProgressHUD *HUD;
}
Then Write the following methods in 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];
}
Then,
// To Remove the Loading View from current view
- (void)removeOnWindow {
// Do something useful in here instead of sleeping ...
[HUD removeFromSuperview];
}
Now, Call the methods onClick events....
// 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];
}
}