Alex Rivera | Logout

How can I show alertview with activity indicator?

Asked 2011-02-05T12:02:05.560
22

I want to show alertview with message: "Loading data" and spinning activity indicator. How can I do this?

Edit
Report

1 Answer

1

Add This in your .h file UIAlertView *connectingAlert;

And Add these two functions in your .m files

//show loading activity.
- (void)startSpinner:(NSString *)message {
    //  Purchasing Spinner.
    if (!connectingAlert) {
        connectingAlert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(message,@"")
                                                 message:nil
                                                delegate:self
                                       cancelButtonTitle:nil
                                       otherButtonTitles:nil];
        connectingAlert.tag = (NSUInteger)300;
        [connectingAlert show];

        UIActivityIndicatorView *connectingIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
        connectingIndicator.frame = CGRectMake(139.0f-18.0f,50.0f,37.0f,37.0f);
        [connectingAlert addSubview:connectingIndicator];
        [connectingIndicator startAnimating];

    }
}
//hide loading activity.
- (void)stopSpinner {
    if (connectingAlert) {
        [connectingAlert dismissWithClickedButtonIndex:0 animated:YES];
        connectingAlert = nil;
    }
    // [self performSelector:@selector(showBadNews:) withObject:error afterDelay:0.1];
}

then call

[self startSpinner:@"Your message........"];
[self stopSpinner];
answered 2013-05-30T11:58:52.410

Your Answer