My Blog List

Android FirstAid Coding

A Small Help From a Small Heart
Powered by Blogger.

A software professional, who still likes to code, likes to blog and loves gadgets.

Showing posts with label How to add UIActivityIndicator to UIAlertView. Show all posts
Showing posts with label How to add UIActivityIndicator to UIAlertView. Show all posts

Monday, 29 April 2013

Showing Activity Indicator Within UIAlertview in Iphone

ViewController.h
================

@interface ViewController : UIViewController{
    UIAlertView *alertLoader;
}

@end

ViewController.m
================

- (void)viewDidLoad
{
    [super viewDidLoad];  
    [self methodtocallWebservices];
}
-(void)methodtocallWebservices{   
    alertLoader = [[UIAlertView alloc] initWithTitle:@"" message:@"Please Wait..." delegate:self cancelButtonTitle:nil otherButtonTitles:nil];
    alertLoader.tag=1;
    [alertLoader show];   
}
- (void)didPresentAlertView:(UIAlertView *)alertView
{  
    if (alertView.tag== 1) {
        UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];       
        indicator.center = CGPointMake(alertView.bounds.size.width/2, alertView.bounds.size.height/3 * 2);       
        [indicator startAnimating];
        [alertView addSubview:indicator];       
        NSString *hostStr = @"@"http://rajuandroid.blogspot.com/api/contact_name_json";       
        NSURL *url = [[NSURL alloc] initWithString:hostStr];
        NSLog(@"login url:  %@",url);       
        NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
        [[[NSURLConnection alloc] initWithRequest:request delegate:self] autorelease];
        [url release];
    }   
}
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data{
  //  [self.receivedData appendData:data];
}

-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error{
    [self stopLoading];
    //[self handleError:error];
}

-(void)connectionDidFinishLoading:(NSURLConnection *)connection{
    [self stopLoading];  
}
-(void)stopLoading
{
    dispatch_async(dispatch_get_main_queue(), ^{
        [alertLoader dismissWithClickedButtonIndex:0 animated:YES];
        [alertLoader release];
    });
}