相对于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. Java常用的集合类(转)

    继上一篇文章http://www.cnblogs.com/EasonJim/p/6937690.html中介绍的集合类有非常多,但是在实际使用中,最常用的应该是下面这几种: Java的集合框架分为Li ...

  2. WIP - 离散任务点击组件-错误:LOCATOR.CONTROL 的变元无效:ORG_LOCATOR_CONTROL=''

    Getting Error "Invalid Argument to LOCATOR.CONTROL: ORG_LOCATOR_CONTROL='' in Material Requirem ...

  3. 重新认识一遍JavaScript

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  4. 关于Activity启动模式(launchMode)和intent设置测试后 发现和网上说的不符 是不是我错了 求解

    看了很多关于Activity启动模式(launchMode)和intent设置intent.setFlags (Intent.FLAG_ACTIVITY_NEW_TASK);发现网上说的和我测试结果 ...

  5. iOS开发核心语言Objective C —— 面向对象思维、setter和getter方法及点语法

    本分享是面向有意向从事iOS开发的伙伴们.或者已经从事了iOS的开发人员.假设您对iOS开发有极高的兴趣,能够与我一起探讨iOS开发.一起学习,共同进步.假设您是零基础,建议您先翻阅我之前分享的iOS ...

  6. ActiveMQ(五) 转

    package pfs.y2017.m11.mq.activemq.demo05; import javax.jms.Connection; import javax.jms.ConnectionFa ...

  7. mybatis 动态curd

    xml <select id="selectByCondition" parameterType="com.oracle.pojo.Student" re ...

  8. Python演绎的精彩故事(二)

    书接上回.在展示了App最顶层的代码后,我们去看看各模块怎样编程. 为了能看懂各模块的代码,首先须要铺垫一下Softchip架构的基本概念和设计规范. 1.随意模块不持有其它模块的实例.自然不再显式使 ...

  9. Arcgis Engine(ae)接口详解(1):featureClass

    //IFeatureClass 来源请自行解决 IFeatureClass featureClass = null; //获取featureClass的各种名称 //PS:featureClass可以 ...

  10. HDU 3249 Test for job (有向无环图上的最长路,DP)

     解题思路: 求有向无环图上的最长路.简单的动态规划 #include <iostream> #include <cstring> #include <cstdlib ...