How can I show alertview with activity indicator?

Voloda2 picture Voloda2 · Feb 5, 2011 · Viewed 31.4k times · Source

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

Answer

jowie picture jowie · May 24, 2012

NOTE: This solution won't work on iOS 7 and above.

This is my take on it:

alertView = [[UIAlertView alloc] initWithTitle:@"Submitting Entry"
                                       message:@"\n"
                                      delegate:self
                             cancelButtonTitle:nil
                             otherButtonTitles:nil];

UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];   
spinner.center = CGPointMake(139.5, 75.5); // .5 so it doesn't blur
[alertView addSubview:spinner];
[spinner startAnimating];
[alertView show];

and dismiss in code using:

[alertView dismissWithClickedButtonIndex:0 animated:YES];