博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
iOS9 UIAlertController简单使用代码
阅读量:2221 次
发布时间:2019-05-08

本文共 1192 字,大约阅读时间需要 3 分钟。

iOS9 xcode7以后,很多方法都过期了,被新的方法所代替。在这里我主要介绍两个常用的控件——UIAlertView、UIActionSheet被替代的新控件——UIAlertController的使用。

一、UIAlertController的UIActionSheet效果时的用法

UIAlertController * sheet = [UIAlertController alertControllerWithTitle:nil message:@"选择性别" preferredStyle:UIAlertControllerStyleActionSheet];[sheet addAction:[UIAlertAction actionWithTitle:@"男" style:UIAlertActionStyleDefault handler:^(UIAlertAction *_Nonnull action) {   NSLog(@"在这里处理选择之后的事");}]];[sheet addAction:[UIAlertAction actionWithTitle:@"女" style:UIAlertActionStyleDefault handler:^(UIAlertAction *_Nonnull action) {   NSLog(@"在这里处理选择之后的事");}]];[sheet addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil]];[self presentViewController:sheet animated:YES completion:nil];

二、UIAlertController的UIAlertView效果时的用法

UIAlertController * alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"请输入手机号" preferredStyle:UIAlertControllerStyleAlert];UIAlertAction *okAction = [UIAlertActionactionWithTitle:@"确定"style:(UIAlertActionStyleCancelhandler:^(UIAlertAction *action) {    NSLog(@"在这里处理点击按钮之后的事"); }]; [alert addAction:okAction]; [self presentViewController:alert animated:YES completion:nil];

转载地址:http://xbifb.baihongyu.com/

你可能感兴趣的文章
【LEETCODE】228-Summary Ranges
查看>>
【LEETCODE】27-Remove Element
查看>>
【LEETCODE】66-Plus One
查看>>
【LEETCODE】26-Remove Duplicates from Sorted Array
查看>>
【LEETCODE】118-Pascal's Triangle
查看>>
【LEETCODE】119-Pascal's Triangle II
查看>>
【LEETCODE】190-Reverse Bits
查看>>
【LEETCODE】67-Add Binary
查看>>
【LEETCODE】223-Rectangle Area
查看>>
【LEETCODE】12-Integer to Roman
查看>>
【学习方法】如何分析源代码
查看>>
【LEETCODE】61- Rotate List [Python]
查看>>
【算法】- 动态规划的编织艺术
查看>>
用 TensorFlow 让你的机器人唱首原创给你听
查看>>
深度学习的主要应用举例
查看>>
word2vec 模型思想和代码实现
查看>>
怎样做情感分析
查看>>
用深度神经网络处理NER命名实体识别问题
查看>>
用 RNN 训练语言模型生成文本
查看>>
RNN与机器翻译
查看>>