IOS 9 以后 UIAlertView就不被苹果所推荐使用了,因此苹果推出了 UIAlerTController来取代UIAlertView,下面介绍下UIAlerTController的使用方式。
Tips:这个
UIAlertController需要版本限制
IOS8.0以上
才可以使用
UIAlertController* alert=[UIAlertControlleralertControllerWithTitle:nilmessage:@"提示" preferredStyle:UIAlertControllerStyleAlert];
[alert addAction:[UIAlertActionactionWithTitle:@"确定" style:UIAlertActionStyleDefaulthandler:^(UIAlertAction*_Nonnullaction)
{
//这里是点击确定按钮以后需要实现的代码
}]];
[alert addAction:[UIAlertActionactionWithTitle:@"取消" style:UIAlertActionStyleCancelhandler:^(UIAlertAction* _Nonnullaction)
{
//这里是点击取消按钮以后需要实现的代码
}]];
[alert addAction:[UIAlertActionactionWithTitle:@"警告"style:UIAlertActionStyleDestructivehandler:^(UIAlertAction*_Nonnullaction)
{
//这里是点击取消按钮以后需要实现的代码
}]];
[selfpresentViewController: alert animated:YEScompletion:nil];
//必要时需要返回主程序调用方法
// dispatch_sync(dispatch_get_main_queue(), ^(){
// // 这里的代码会在主线程执行
// [self presentViewController:_alertViewErroranimated:YES completion:nil];
//
// });