UIAlertController的基本使用

18-10-23 00:24 字数 776 阅读 2466 已编辑

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

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

0人点赞>
关注 收藏 改进 举报
0 条评论
排序方式 时间 投票
快来抢占一楼吧
请登录后发表评论
站长 @ 十七度
文章
380
粉丝
23
喜欢
190
收藏
31
排名 : 1
访问 : 127.95万
私信