相对于IOS8.4之后苹果对提示框做了进一步的封装,这将与之前的提示框有很大的同。

之前的 UIAlterView  是弹出一个提示框。

而今天学习的提示框是 通过视图控制器进行弹出,这就意味着,我们可以在这个提示框上添加更多的处理事件,我认为苹果的之所以这样是希望用户能够将提示框的功能发挥的淋漓尽致,效果会更加的炫酷。

这里仅仅将基础知识写出来,以供查阅与巩固。

UIAlertController * alterCon = [UIAlertController alertControllerWithTitle:@"提示" message:@"不需要" preferredStyle:UIAlertControllerStyleActionSheet];

UIAlertAction * alterTion = [UIAlertAction actionWithTitle:@"警告" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {

}];

[alterCon addAction:alterTion];

[self presentViewController:alterCon animated:NO completion:nil];

实际上提示的内容是:alterCon 里面定义的提示内容。

在alterCon 里 有的一个属性值(就是上面写的) :UIAlertControllerStyleActionSheet 是让提示框从底部出现。

还有一个属性值:UIAlertControllerStyleAlert 是让提示框从中部出现。

资料参考

有的时候,我们希望实现如下的效果:

上面的代码实现的效果的关键源代码:

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
UIAlertController * alterCon = [UIAlertController alertControllerWithTitle:@"提示" message:@"你好,你可以这样做更好,请【确定】;你好,你可以这样做更好,请【取消】;你好,你可以这样做更好,请【稍后在说】" preferredStyle:UIAlertControllerStyleActionSheet];
UIAlertAction * alterTion1 = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
NSLog(@"选择了这个——确定");
}];
UIAlertAction * alterTion2 = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
NSLog(@"选择了这个——取消");
}];
UIAlertAction * alterTion3 = [UIAlertAction actionWithTitle:@"稍后在说" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
NSLog(@"选择了这个——稍后再说");
}];
[alterCon addAction:alterTion1];
[alterCon addAction:alterTion2];
[alterCon addAction:alterTion3];
[self presentViewController:alterCon animated:NO completion:nil];
}
代码

此外也可以实现下面的效果:

实现效果代码为:

UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"添加好友" preferredStyle:UIAlertControllerStyleAlert];

    [alert addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {

    }];

    UITextField *textField = alert.textFields[];

    UIAlertAction *queding = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
// 发起好友的添加请求 }];
UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
[alert addAction:queding];
[alert addAction:cancel]; // 显示警示框
[self presentViewController:alert animated:YES completion:nil];
代码

UIAlterController 的使用的更多相关文章

  1. 解决 UIAlterController 不居中问题

    最后更新:2017-06-30 现象描述 新公司做的解决的第一个bug 就是 UIAlterController 不居中,莫名其妙的飞出屏幕之外 找了很久的答案,最终在苹果论坛看到了相关的描述 We ...

  2. Android开发之基本控件和详解四种布局方式

    Android中的控件的使用方式和iOS中控件的使用方式基本相同,都是事件驱动.给控件添加事件也有接口回调和委托代理的方式.今天这篇博客就总结一下Android中常用的基本控件以及布局方式.说到布局方 ...

  3. Android-基本控件和详解四种布局方式

    转自:https://www.cnblogs.com/ludashi/p/4883915.html 一.常用基本控件 1.TextView 看到Android中的TextView, 我不禁的想到了iO ...

随机推荐

  1. LeetCode第一题以及时间复杂度的计算

    问题描述:给定一组指定整数数组,找出数组中加和等于特定数的两个数. 函数(方法)twoSum返回这两个数的索引,index1必须小于index2. 另外:你可以假设一个数组只有一组解. 一个栗子: I ...

  2. Ubuntu 16.04通过Snap安装应用程序

    16.04LTS可以说是一个不寻常的5年支持版本,同时也带来了Snap应用,并通过Snap可以安装众多的软件包.需要注意的是,Snap是一个全新的软件包架构,但是同样也比其它的软件包大很多. 简单的安 ...

  3. java 使用POI读取excel数据

    原文:http://doc.okbase.net/0201zcr/archive/161440.html 一.定义 Apache POI是Apache软件基金会的开放源码函式库,POI提供API给Ja ...

  4. 【spring boot Mybatis】报错:org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.newhope.interview.dao.UserMapper.add

    报错如下: org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.newhope.i ...

  5. pycharm整体缩进的快捷键

    选中多行,按tab进行缩进,按tab+shift去除缩进

  6. Java面试题集(151-180)

    摘要:这部分包括了Spring.Spring MVC以及Spring和其它框架整合以及測试相关的内容,除此之外还包括了大型站点技术架构相关面试内容. 151. Spring中的BeanFactory和 ...

  7. keras常见问题解答

    https://keras.io/zh/getting-started/faq/ https://keras.io/zh/ https://github.com/keras-team/keras/tr ...

  8. tcp三次握手和syn 洪水攻击

    1. 连接后,所有的 ack 为1才有效(连接后,ack 也一般都是1) 2. 建立连接3次握手, 如何确认对方收到了你发的包, seq 是自己发出去的,自己知道seq的值.所以怎么确认对方收到了自己 ...

  9. time machine不备份指定文件夹

    osx中常常会使用timemachine来备份一些文件,timemachine能够使某个文件夹恢复到之前某个时刻的状态,很的方便.但是备份须要空间,特别是有些我们并不想备份一些无关紧要的文件,比方电影 ...

  10. SolidEdge 如何绘制零件图的剖视图

    1 点击检视-剖面,然后选择剖切面   2 比如要全剖,则绘制好方框之后点返回,选择方向.   选择剖切深度,然后预览即可   一个零件可以进行多次剖切