ios定时自动退出UIAlertView提示框

来源:互联网 发布:最知女人心 编辑:程序博客网 时间:2024/05/22 12:36
今天想在应用里加个自动退出提示框的功能,在网上没找到好的方法,所以自己用定时器做了一个,跟大家分享下,如果有其他更好的方法麻烦提示一下。

//对话框的创建和定时器的初始化
alertView = [[UIAlertView alloc] initWithTitle:@"Result" message:@"Share Success" delegate:nil cancelButtonTitle:nil otherButtonTitles:nil, nil];
    [alertView show];
    NSTimer *timer = [[NSTimer timerWithTimeInterval:3 target:self selector:@selector(onTimer) userInfo:nil repeats:NO] retain];
    [[NSRunLoop currentRunLoop] addTimer:timer forMode:NSDefaultRunLoopMode];
    [timer release];


//timer的执行事件
- (void)onTimer
{
    [alertView dismissWithClickedButtonIndex:0 animated:NO];  //退出对话框
}
原创粉丝点击