#import "UITestViewController.h"
NSTimer *timer;
@implementation UITestViewController
- (void)hideAlert:(NSTimer *)sender
{
UIAlertView *alert = [sender userInfo];
[alert dismissWithClickedButtonIndex:0 animated:YES];
}
- (void)viewDidLoad {
[super viewDidLoad];
UIAlertView *myAlert = [[UIAlertView alloc] initWithTitle:@"title"
message:@"This alert will disappear in 3 seconds"
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[myAlert addButtonWithTitle:@"new button"];
[myAlert addButtonWithTitle:@"another button"];
[myAlert show];
//create a timer to hide the alert automatically in 3 seconds
timer = [[NSTimer scheduledTimerWithTimeInterval:3.0 target:self selector:@selector(hideAlert:) userInfo:myAlert repeats:NO] retain];
[myAlert release];
}
转载于:https://www.cnblogs.com/foxmin/archive/2012/03/13/2393607.html