步骤一、初始化:

 UIAlertController * inputname = [UIAlertController alertControllerWithTitle:@"未输入账户" message:@"请输入账户名" preferredStyle:UIAlertControllerStyleAlert];

步骤二、添加按钮:

 [inputname addAction:[UIAlertAction actionWithTitle:@"知道了" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {

             ;//点击知道了之后可以出发的事件

         }]];

步骤三、添加一个UITextField用来输入:

 [inputname addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
textField.placeholder = @"请再次输入密码";
textField.clearButtonMode = UITextFieldViewModeWhileEditing;
}];

步骤四、呈现:

 [self presentViewController:inputname animated:YES completion:^{
;//呈现出来之后执行的事件
}];

例子:

1、上面添加一个简单的知道了按钮:

 //       1、创建一个UIAlertController并初始化
UIAlertController * inputname = [UIAlertController alertControllerWithTitle:@"未输入账户" message:@"请输入账户名" preferredStyle:UIAlertControllerStyleAlert];
// 2、添加一个“知道了”按钮
[inputname addAction:[UIAlertAction actionWithTitle:@"知道了" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { ;//点击知道了之后可以出发的事件 }]];
// 3、把设置好的UIAlertController呈现在屏幕上
[self presentViewController:inputname animated:YES completion:^{
;//呈现出来之后执行的事件
}];

2、上面添加取消、确定、以及三个文本输入框(用来作为注册账号的弹出框):

 UIAlertController * registerAlertC = [UIAlertController alertControllerWithTitle:@"注册新用户" message:nil preferredStyle:UIAlertControllerStyleAlert];

     [registerAlertC addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
textField.placeholder = @"请输入用户名";
textField.clearButtonMode = UITextFieldViewModeWhileEditing;
}]; [registerAlertC addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
textField.placeholder = @"请输入密码";
textField.clearButtonMode = UITextFieldViewModeWhileEditing;
}]; [registerAlertC addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
textField.placeholder = @"请再次输入密码";
textField.clearButtonMode = UITextFieldViewModeWhileEditing;
}]; [registerAlertC addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
;
}]]; [registerAlertC addAction:[UIAlertAction actionWithTitle:@"注册" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
UITextField *name = [registerAlertC.textFields objectAtIndex:];
UITextField *mima1 = [registerAlertC.textFields objectAtIndex:];
UITextField *mima2 = [registerAlertC.textFields objectAtIndex:]; if ([name.text isEqualToString:@""]) {
UIAlertController * worning1 = [UIAlertController alertControllerWithTitle:@"用户名不能为空" message:nil preferredStyle:UIAlertControllerStyleAlert];
[worning1 addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
;
}]];
[self presentViewController:worning1 animated:YES completion:^{
;
}]; }else{
if ([mima2.text isEqualToString:mima1.text]) {
// 注册成功
// 使用单例把账户密码保存起来
NSString *mima = mima1.text;
NSString *zhanghu = name.text; NSUserDefaults *User =[NSUserDefaults standardUserDefaults];
[User setObject:mima forKey:zhanghu];
UIAlertController * success = [UIAlertController alertControllerWithTitle:@"注册成功" message:nil preferredStyle:UIAlertControllerStyleAlert];
[success addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
;
}]];
[self presentViewController:success animated:YES completion:^{
;
}]; }else{
// 两次输入密码不一致
UIAlertController * worning2 = [UIAlertController alertControllerWithTitle:@"两次输入密码不一致" message:nil preferredStyle:UIAlertControllerStyleAlert];
[worning2 addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
;
}]];
[self presentViewController:worning2 animated:YES completion:^{
;
}]; } } }]];

IOS开发中UIAlertController(警告框)的使用的更多相关文章

  1. iOS开发中的4种数据持久化方式【二、数据库 SQLite3、Core Data 的运用】

                   在上文,我们介绍了ios开发中的其中2种数据持久化方式:属性列表.归档解档.本节将继续介绍另外2种iOS持久化数据的方法:数据库 SQLite3.Core Data 的运 ...

  2. iOS开发中你是否遇到这些经验问题

    前言 小伙伴们在开发中难免会遇到问题, 你是如何解决问题的?不妨也分享给大家!如果此文章其中的任何一条问题对大家有帮助,那么它的存在是有意义的! 反正不管怎样遇到问题就要去解决问题, 在解决问题的同时 ...

  3. ios 开发中 动态库 与静态库的区别

    使用静态库的好处 1,模块化,分工合作 2,避免少量改动经常导致大量的重复编译连接 3,也可以重用,注意不是共享使用 动态库使用有如下好处: 1使用动态库,可以将最终可执行文件体积缩小 2使用动态库, ...

  4. iOS开发中打电话发短信等功能的实现

    在APP开发中,可能会涉及到打电话.发短信.发邮件等功能.比如说,通常一个产品的"关于"页面,会有开发者的联系方式,理想情况下,当用户点击该电话号码时,能够自动的帮用户拨出去,就涉 ...

  5. iOS开发中的4种数据持久化方式【一、属性列表与归档解档】

    iOS中的永久存储,也就是在关机重新启动设备,或者关闭应用时,不会丢失数据.在实际开发应用时,往往需要持久存储数据的,这样用户才能在对应用进行操作后,再次启动能看到自己更改的结果与痕迹.ios开发中, ...

  6. iOS开发中关于UIImage的知识点总结

    UIImage是iOS中层级比较高的一个用来加载和绘制图像的一个类,更底层的类还有 CGImage,以及iOS5.0以后新增加的CIImage.今天我们主要聊一聊UIImage的三个属性: image ...

  7. IOS开发中重写init方法使用需谨慎

    IOS开发中重写init方法使用需谨慎 今天在写一个小软件的时候出现一点问题,这个软件的功能是搜索全国学校,首页就是搜索输入框,在框中输入完要查询的学校所在省份,点击buttom后就会跳转到对应的视图 ...

  8. IOS开发中如何判断程序第一次启动(根据判断结果决定是否显示新手操作引导)

    IOS开发中如何判断程序第一次启动 在软件下载安装完成后,第一次启动往往需要显示一个新手操作引导,来告诉用户怎么操作这个app,这就需要在程序一开始运行就判断程序是否第一次启动,如果是,则显示新手操作 ...

  9. iOS开发中视图控制器ViewControllers之间的数据传递

    iOS开发中视图控制器ViewControllers之间的数据传递 这里我们用一个demo来说明ios是如何在视图控制器之间传递重要的参数的.本文先从手写UI来讨论,在下一篇文章中讨论在storybo ...

随机推荐

  1. Linux关闭防火墙,关闭Selinux

    查看防火墙状态 iptables -L or service iptables status 临时性关闭防火墙 iptables -F or service iptables stop 永久性关闭防火 ...

  2. C1 FlexGrid控件 Editor 冲突问题

    当给C1FlexGrid控件加入 Checkbox后,添加新行时对新行的Editor 赋新控件时,会冲突如下图:       下面我们借助BeforeRowColChange 事件来解决这个问题: 我 ...

  3. mysql笔记6之数据类型

    1 区别一: varchar:可变长度的字符串.根据添加的数据长度决定占用的字符数 char:固定长度的字符串 2区别二 int:没有限制 int(4):限制为4 3 区别三: 日期: date    ...

  4. PAT1006

    At the beginning of every day, the first person who signs in the computer room will unlock the door, ...

  5. LISTVIEW嵌套GRIDVIEW的一些处理(点击GRIDVIEW的条目,能够显示他在LISTVIEW中的位置)(对这篇文章的优化处理,不每次都new onItemClickListener)

    前几天写了点击GRIDVIEW的条目,能够显示他在LISTVIEW中的位置,当时的处理是在ListView的适配器里的GetView方法里每次都new GridView的onItemClickList ...

  6. 在Gridview编辑时添加DropDownList控件并设置默认值

    页面代码: <asp:GridView ID="GridView1" runat="server"             AutoGenerateCol ...

  7. PAT (Advanced Level) 1056. Mice and Rice (25)

    简单模拟. #include<iostream> #include<cstring> #include<cmath> #include<algorithm&g ...

  8. 一个门外汉的理解 ~ Faster R-CNN

    首先放R-CNN的原理图 显然R-CNN的整过过程大致上划分为四步: 1.输入图片 2.生成候选窗口 3.对局部窗口进行特征提取(CNN) 4.分类(Classify regions) 而R-CNN的 ...

  9. UITextField和UIViewConteoller

    UITextField控件 UITextFiled常用属性和方法   UITextField是常用的文本输入控件,比如我们用的QQ的登录界面,词典输入要查询的单词都使用了文本框控件,如下图所示.之前介 ...

  10. PHP 将MySQL数据导出csv

    1.查询数据 // 假设得到的数据格式如下 $result = array( array( "orderid" = "1110111", "shopi ...