Follow Me on Twitter
<div style="background-color: none transparent;"><a href="http://www.rsspump.com/?web_widget/rss_widget/twitter_widget" title="web widget">Twitter Widget</a></div>

iPhone SDK UIAlertView With Activity Indicator

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];
Wednesday ( 2 / 17 / 2010 )

blog comments powered by Disqus