How can I show alertview with activity indicator?
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];
This works on iOS 7
addSubView doesn't work on UIAlertView in iOS 7 and above. Try this instead
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Loading data" message:nil delegate:nil cancelButtonTitle:nil otherButtonTitles: nil];UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];[indicator startAnimating];[alertView setValue:indicator forKey:@"accessoryView"];[alertView show];
and to dismiss it
[alertView dismissWithClickedButtonIndex:0 animated:YES];
you can add a label and activityindicator as subviews of your alert view. you have to do some thing like this
myAlertView = [[UIAlertView alloc] initWithTitle:@"Loading" message:@"\n\n" delegate:self cancelButtonTitle:@"" otherButtonTitles:@"OK", nil]; UIActivityIndicatorView *loading = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray]; loading.frame=CGRectMake(150, 150, 16, 16);[myAlertView addSubview:loading];[myAlertView show];
..better to use a UIActionSheet in this situation...