# UIAlertController的基本使用

**URL:** <https://www.shiqidu.com/t/topic/503>\
**Category:** 开发调优\
**Tags:** C-C-Obj-C\
**Created:** [2018 年10 月 22 日 16:24 UTC](https://www.shiqidu.com/t/topic/503 "2018-10-22T16:24:35Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

作者： ![Eureka](https://www.shiqidu.com/user_avatar/www.shiqidu.com/eureka/32/5_2.png) [@Eureka](https://www.shiqidu.com/u/Eureka)\
发布日期： [2018 年10 月 22 日 16:24 UTC](https://www.shiqidu.com/t/topic/503/1 "2018-10-22T16:24:35Z")

</div>

`UIActionSheet`和`UIAlertView`都被弃用了， 想要显示弹窗或者actionSheet可以使用`UIAlertController`，`UIAlertController`兼具二者功能，并且能做的更多，本文只演示如何显示一个actionSheet。

```oc
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"确定退出？" message:nil preferredStyle:UIAlertControllerStyleActionSheet];
    
UIAlertAction *aAction1 = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
    NSLog(@"点击了取消");
}];

UIAlertAction *aAction2 = [UIAlertAction actionWithTitle:@"确定退出" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
    NSLog(@"点击了确定");
    [self.navigationController popViewControllerAnimated:YES];
}];

[alertController addAction:aAction1];
[alertController addAction:aAction2];

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

```

效果图

![UIAlertController](https://discourse.shiqidu.com/upload/discussion/20181023/7104e368ee234286985f5f08c8a25bc0_origin.png)
