[置顶] iOS8禁止使用UIAlertView后,苹果提供的UIAlertController的使用方法

// 弹出确定取消按钮

UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"输入信息有误,请重新输入message:nil preferredStyle:UIAlertControllerStyleAlert];

UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"好的style:UIAlertActionStyleDefault handler:nil];

[alertController addAction:okAction];

UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:nil];

[alertController addAction:cancelAction];

[self presentViewController:alertController animated:YES completion:nil];

// 1秒后自动消失

UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"输入信息有误,请重新输入message:nil preferredStyle:UIAlertControllerStyleAlert];

[self presentViewController:alertControlleranimated:YES completion:nil];

[NSTimer scheduledTimerWithTimeInterval:target:self selector:@selector(creatAlert:) userInfo:alertControllerrepeats:NO];


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

    UIAlertController *alert = [timer userInfo];

    [alert dismissViewControllerAnimated:YES completion:nil];

    alert = nil;

}


你可能感兴趣的:(ios开发)