首页 技术 正文
技术 2022年11月17日
0 收藏 318 点赞 3,729 浏览 2257 个字

相对于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 是让提示框从中部出现。

资料参考

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

UIAlterController 的使用

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

-(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];
}
代码

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

UIAlterController 的使用

实现效果代码为:

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];
代码
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,991
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,505
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,349
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,134
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,766
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,844