UIAlertView 自动消失

来源:互联网 发布:mac登陆远程桌面 编辑:程序博客网 时间:2024/05/17 07:10

- (void)showAlert{

    

    UIAlertView *alert = [[UIAlertViewalloc]initWithTitle:@"提示"message:@"2秒后将消失"delegate:nil cancelButtonTitle:nilotherButtonTitles:nil];

    

    [alertshow];

   // 2秒后执行

dispatch_time_t time = dispatch_time(DISPATCH_TIME_NOW, 2*NSEC_PER_SEC);
        dispatch_after(time, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
            [alert dismissWithClickedButtonIndex:[alert cancelButtonIndex] animated:YES];
        });   

}