【代码笔记】iOS-UIAlertView3秒后消失

一,效果图。

二,代码。

复制代码
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    UIAlertView* alert = [[UIAlertView alloc]initWithTitle:nil message:@"此信息3秒后消失" delegate:nil cancelButtonTitle:nil otherButtonTitles:nil, nil];
    [alert show];

    [self performSelector:@selector(dismissAlert:) withObject:alert afterDelay:3.0];
}
- (void)dismissAlert:(UIAlertView*)alert {
    if ( alert.visible ) {
        [alert dismissWithClickedButtonIndex:alert.cancelButtonIndex animated:YES];
    }
}
原文地址:https://www.cnblogs.com/yang-guang-girl/p/8003811.html