iPhone控件之UIAlertView

#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];
}
posted @ 2012-03-13 12:56  FoxBabe  阅读(251)  评论(0编辑  收藏  举报