UIIAlertController的自动消失

自动消失的思路就是添加一个计时器,设置计时器的时间,让UIAlertController 通过dismiss消失


UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"没有上一部了" preferredStyle:UIAlertControllerStyleAlert];

        [self presentViewController:alert animated:NO completion:nil];

        [NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(creatAlert:) userInfo:alert repeats:NO];


- (void)creatAlert:(NSTimer *)timer{

    UIAlertController *alert = [timer userInfo];

    [alert dismissViewControllerAnimated:YES completion:nil];

    alert = nil;


}



你可能感兴趣的:(UI)