UIAlertController:弹框4步走

对于大多数的App来说,弹框这种交互方式基本上是必不可少的。在新的iOS系统中(具体版本我忘了),以前的UIAlertView被弃用,而换成了现在的UIAlertController。

UIAliterController的使用方式与之前的UIAlterView的区别还是比较大的,刚开始用可能需要学习一下。典型的使用方法如下:

1         UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"邮箱格式不正确" message:@"请正确输入邮箱地址" preferredStyle:UIAlertControllerStyleAlert];
2         UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil];
3         [alert addAction:okAction];
4         [self presentViewController:alert animated:YES completion:nil];

一共分为4步:

1.实例化一个UIAlertController,并且赋以标题和内容以及Alert的Style

2.实例化一个Action,并赋以Action的标题、Style以及Action的Handler block

3.将actoin赋给 第1步定义的AlertController

4.显示AlterController,并且定义Alert消失后的操作的block

posted @ 2016-08-22 15:20  Oooliver  阅读(297)  评论(0编辑  收藏  举报
为用户提供更好的解决方案,技术改变世界