DismissingAlertView

Automatically dismissing UIAlertView.

DismissingAlertView.h

//
//  DismissingAlertView.h
//
//  Created by hytgbn on 10. 4. 29..
//  Copyright 2010 hytgbn. All rights reserved.
//

#import <Foundation/Foundation.h>

@protocol DismissingAlertViewDelegate 

-(void)onDismissingAlertView:(id)control;

@end

@interface DismissingAlertView : UIAlertView <UIAlertViewDelegate> {
	id<DismissingAlertViewDelegate> dismissingDelegate;
}

@property(nonatomic, assign) id<DismissingAlertViewDelegate> dismissingDelegate;

+ (id)alertWithTitle:(NSString *)title message:(NSString*)msg interval:(NSTimeInterval)ti delegate:(id<DismissingAlertViewDelegate>)obj;
+ (id)alertWithTitle:(NSString *)title message:(NSString*)msg interval:(NSTimeInterval)ti;

@end

DismissingAlertView.m

//
//  DismissingAlertView.m
//
//  Created by hytgbn on 10. 4. 29..
//  Copyright 2010 hytgbn. All rights reserved.
//

#import "DismissingAlertView.h"


@implementation DismissingAlertView

@synthesize dismissingDelegate;

+ (id)alertWithTitle:(NSString *)title message:(NSString*)msg interval:(NSTimeInterval)ti delegate:(id<DismissingAlertViewDelegate>)obj {
	DismissingAlertView *alertView = nil;
	if( alertView = [[super alloc] initWithTitle:title message:msg delegate:self cancelButtonTitle:nil otherButtonTitles:nil] ) {
		
		[NSTimer scheduledTimerWithTimeInterval:2 target:alertView selector:@selector(hideUI:) userInfo:nil repeats:NO];
		[alertView setDismissingDelegate:obj];
		[alertView show];
		
	}
	return [alertView autorelease];
}

+ (id)alertWithTitle:(NSString *)title message:(NSString*)msg interval:(NSTimeInterval)ti {
	return [DismissingAlertView alertWithTitle:title message:msg interval:ti delegate:nil];
}

- (void)hideUI:(NSTimer *)timer {
	[self dismissWithClickedButtonIndex:0 animated:NO];	 
	
	if( dismissingDelegate != nil ) {
		[dismissingDelegate onDismissingAlertView:self];
	}
}

@end

Usage :

    [DismissingAlertView alertWithTitle:@"Error" message:@"You got the error!" interval:3.0];

Also you can get dismissing event.
self implements DismissingAlertViewDelegate

    [DismissingAlertView alertWithTitle:@"Error" message:@"You got the error!" interval:3.0 delegate:self];

Comments

comments