让alert view自动消失

UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"抱歉" message:@"暂未开放登录注册功能" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *actionCancel = [UIAlertAction actionWithTitle:@"哦" style:UIAlertActionStyleDefault handler:nil];
 
[alertController addAction:actionCancel];
   
[self presentViewController:alertController animated:YES completion:nil];
  
#pragma mark - 让alert自动消失
[NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(creatAlert:) userInfo:alertController repeats:NO];


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

    UIAlertController *alert = [timer userInfo];

    [alert dismissViewControllerAnimated:YES completion:nil];

    alert = nil;

}

你可能感兴趣的:(让alert view自动消失)