UIAlterController 的使用
相对于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 的使用的更多相关文章
- 解决 UIAlterController 不居中问题
最后更新:2017-06-30 现象描述 新公司做的解决的第一个bug 就是 UIAlterController 不居中,莫名其妙的飞出屏幕之外 找了很久的答案,最终在苹果论坛看到了相关的描述 We ...
- Android开发之基本控件和详解四种布局方式
Android中的控件的使用方式和iOS中控件的使用方式基本相同,都是事件驱动.给控件添加事件也有接口回调和委托代理的方式.今天这篇博客就总结一下Android中常用的基本控件以及布局方式.说到布局方 ...
- Android-基本控件和详解四种布局方式
转自:https://www.cnblogs.com/ludashi/p/4883915.html 一.常用基本控件 1.TextView 看到Android中的TextView, 我不禁的想到了iO ...
随机推荐
- android 获得屏幕宽度和高度
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools= ...
- 【Android小项目】找不同,改编自"寻找房祖名"的一款开源小应用。
近期在微信朋友圈"寻找房祖名"和"万里寻刀"这类小游戏比較火.我试着写了一个android版本号的,里面全是一系列的形近字,实现原理非常easy:用一个Grid ...
- 王立平--GUI与GUILayout的差别
GUI.Button (new Rect(0,0,5,5,"哈哈"); GUILayout.Button ("heheh"); 1.以上代码都是现实一个butt ...
- css设置图片居中、居左、居右
CreateTime--2017年12月8日14:25:09 Author:Marydon css设置图片居中.居左.居右 图片一般默认是居左显示的,如何更改它的水平位置呢? <div st ...
- iOS设计模式 - (3)简单工厂模式
iOS设计模式 - (3)简单工厂模式 by Colin丶 转载请注明出处: http://blog.csdn.net/hitwhylz/article/ ...
- 深入理解Atomic原子操作和volatile非原子性
原子操作可以理解为: 一个数,很多线程去同时修改它,不加sync同步锁,就可以保证修改结果是正确的 Atomic正是采用了CAS算法,所以可以在多线程环境下安全地操作对象. volatile是Java ...
- fatal error C1083: 无法打开预编译头文件:“Debug\opencv.pch”: No such file or directory
stdafx.cpp右键——属性,预编译头选“创建”,其它cpp选“使用”. 调试不能优化.
- JavaScript and ActionScript3
接触JavaScript和ActionScript3也有一段时间了,它们都是应用比较广泛的脚本语言,经过这几年的工作和学习,静下来的时候想总结一些东西,作为技术上的沉淀以及培训所用,所以就有了这篇文章 ...
- Android:在子线程中更新UI的三种方式
①使用Activity中的runOnUiThread(Runnable) ②使用Handler中的post(Runnable) 在创建Handler对象时,必须先通过Context的getMainLo ...
- UIActivityIndicatorView控件的属性和方法
对于UIActivityIndicatorView的使用,我们一般会创建一个背景View,设置一定的透明度,然后将UIActivityIndicatorView贴在背景View上,在我们需要的时候将这 ...