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
@interface ActivityAlertView : UIAlertView
{
UIActivityIndicatorView *activityView;
}
@property (nonatomic, retain) UIActivityIndicatorView *activityView;
- (void) close;
@end
// ActivityAlertView.m
#import "ActivityAlertView.h"
@implementation ActivityAlertView
@synthesize activityView;
- (id)initWithFrame:(CGRect)frame
{
if ((self = [super initWithFrame:frame]))
{
self.activityView = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(125, 80, 30, 30)];
[self addSubview:activityView];
activityView.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;
[activityView startAnimating];
}
return self;
}
- (void) close
{
[self dismissWithClickedButtonIndex:0 animated:YES];
}
- (void) dealoc
{
[activityView release];
[super dealloc];
}
@end
// Usage
// Show the alert activityAlert = [[[ActivityAlertView alloc] initWithTitle:@"Doing Something" message:@"Please wait..." delegate:self cancelButtonTitle:nil otherButtonTitles:nil] autorelease]; [activityAlert show]; //Remove the alert [activityAlert close];



