Looking for a quick and easy way to show an activity indicator? I found the easiest way was to subclass UIAlertView to make a reusable solution. Click read more for the code.

// ActivityAlertView.h
01@interface ActivityAlertView : UIAlertView
02{
03 UIActivityIndicatorView *activityView;
04}
05
06@property (nonatomic, retain) UIActivityIndicatorView *activityView;
07
08- (void) close;
09
10@end
// ActivityAlertView.m
01#import "ActivityAlertView.h"
02
03@implementation ActivityAlertView
04
05@synthesize activityView;
06
07- (id)initWithFrame:(CGRect)frame
08{
09 if ((self = [super initWithFrame:frame]))
10 {
11 self.activityView = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(125, 80, 30, 30)];
12 [self addSubview:activityView];
13 activityView.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;
14 [activityView startAnimating];
15 }
16
17 return self;
18}
19
20- (void) close
21{
22 [self dismissWithClickedButtonIndex:0 animated:YES];
23}
24
25- (void) dealoc
26{
27 [activityView release];
28 [super dealloc];
29}
30
31@end
// Usage
01// Show the alert
02activityAlert = [[[ActivityAlertView alloc]
03 initWithTitle:@"Doing Something"
04 message:@"Please wait..."
05 delegate:self cancelButtonTitle:nil
06 otherButtonTitles:nil] autorelease];
07
08[activityAlert show];
09
10//Remove the alert
11[activityAlert close];