楼主在整理项目的警告,于是乎你懂的。

然后自己整理了一下以后方便自己忘了之后能及时找到它

关于UIAlertController .h文件的解析

/**
关于UIAlertController的解析
*/ #import <UIKit/UIViewController.h>
//
NS_ASSUME_NONNULL_BEGIN //枚举 UIAlertActionStyle
typedef NS_ENUM(NSInteger, UIAlertActionStyle) {
UIAlertActionStyleDefault = ,//默认
UIAlertActionStyleCancel,//取消
UIAlertActionStyleDestructive//颜色突出的
} NS_ENUM_AVAILABLE_IOS(8_0);
//枚举 UIAlertControllerStyle
typedef NS_ENUM(NSInteger, UIAlertControllerStyle) {
UIAlertControllerStyleActionSheet = ,//actionSheet// 从底部弹出
UIAlertControllerStyleAlert//alertView 从中间弹出
} NS_ENUM_AVAILABLE_IOS(8_0); /* ********************************UIAlertAction********************************/
//aletviewCon的内部模块按钮
NS_CLASS_AVAILABLE_IOS(8_0) @interface UIAlertAction : NSObject <NSCopying>
/**
* 类方法创建
*
* @param title 标题内容
* @param style action的样式
* @param handler 点击后执行的操作block模式
*
* @return
*/
+ (instancetype)actionWithTitle:(nullable NSString *)title style:(UIAlertActionStyle)style handler:(void (^ __nullable)(UIAlertAction *action))handler;
@property (nullable, nonatomic, readonly) NSString *title;
@property (nonatomic, readonly) UIAlertActionStyle style;
//是否可点击
@property (nonatomic, getter=isEnabled) BOOL enabled; @end /* ********************************UIAlertController********************************/ NS_CLASS_AVAILABLE_IOS(8_0) @interface UIAlertController : UIViewController
/**
* 工厂方法创建
*
* @param title 标题
* @param message 详细标题
* @param preferredStyle 样式
*
* @return
*/
+ (instancetype)alertControllerWithTitle:(nullable NSString *)title message:(nullable NSString *)message preferredStyle:(UIAlertControllerStyle)preferredStyle;
/**
* 添加按钮
*
* @param action
*/
- (void)addAction:(UIAlertAction *)action;
//按钮数组()只读的
@property (nonatomic, readonly) NSArray<UIAlertAction *> *actions;
//偏好action,将以后的action设置为偏好action,action的字体会加粗
@property (nonatomic, strong, nullable) UIAlertAction *preferredAction NS_AVAILABLE_IOS(9_0);
//alerviewstyle添加文本框的方法 可在block设置textfield的属性
- (void)addTextFieldWithConfigurationHandler:(void (^ __nullable)(UITextField *textField))configurationHandler;
@property (nullable, nonatomic, readonly) NSArray<UITextField *> *textFields;//装有往弹窗添加的文本框的数组(只读) @property (nullable, nonatomic, copy) NSString *title;
@property (nullable, nonatomic, copy) NSString *message;
@property (nonatomic, readonly) UIAlertControllerStyle preferredStyle;//样式(只读) @end NS_ASSUME_NONNULL_END

使用代码

在button点击事件中

- (IBAction)button:(id)sender {
// UIAlertController *alertCon = [UIAlertController alertControllerWithTitle:@"提示" message:@"wocao" preferredStyle:UIAlertControllerStyleActionSheet];
UIAlertController *alertCon = [UIAlertController alertControllerWithTitle:@"提示" message:@"wocao" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *action1 = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
UIAlertAction *action2 = [UIAlertAction actionWithTitle:@"默认" style:UIAlertActionStyleDefault handler:nil];
UIAlertAction *action3 = [UIAlertAction actionWithTitle:@"不知道" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
NSLog(@"wocaodelai ");
}];
// action3.enabled = NO;
[alertCon addAction:action1];
[alertCon addAction:action2];
[alertCon addAction:action3];
alertCon.preferredAction = action3;
[alertCon addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
textField.textColor = [UIColor redColor];
}];
[alertCon addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
textField.textColor = [UIColor yellowColor];
textField.textAlignment = NSTextAlignmentRight;
}];
// NSLog(@"textFields %@", alertCon.textFields);
[self presentViewController:alertCon animated:YES completion:nil];
}

UIAlertController的更多相关文章

  1. iOS UIAlertController跟AlertView用法一样 && otherButtonTitles:(nullable NSString *)otherButtonTitles, ... 写法

    今天写弹出框UIAlertController,用alertView习惯了,所以封装了一下,跟alertView用法一样,不说了,直接上代码: 先来了解一下otherButtonTitles:(nul ...

  2. UIAlertController使用

    // 将UIAlertController模态出来 相当于UIAlertView show 的方法// 初始化一个一个UIAlertController    // 参数preferredStyle: ...

  3. IOS UIAlertController 使用方法

    在很多种语言中,alert都表示弹窗操作,弹窗功能非常有用,不仅可以用于正式的app功能中,也可以在调试中使用.在OC中,UIAlertController类用来控制弹窗操作.在IOS 8.0之前, ...

  4. UI控件(UIAlertController)

    @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; UIButton *_button = [UIBut ...

  5. UIAlertController 部分用法及属性

    //创建UIAlertController:初始化UIAlertController 需要使用alertControllerWithTitle UIAlertController *alertCont ...

  6. iOS--UIAlertView与UIAlertController和UIAlertAction之间的事儿

      iOS 8的新特性之一就是让接口更有适应性.更灵活,因此许多视图控制器的实现方式发生了巨大的变化.全新的UIPresentationController在实现视图控制器间的过渡动画效果和自适应设备 ...

  7. 开始使用 UIAlertController 吧

    UIAlertView 与 UIActionSheet UIAlertView 样式 实现 - (void)showAlertView { self.alertView = [[UIAlertView ...

  8. UI第十四节——UIAlertController

    - (void)viewDidLoad {    [super viewDidLoad];        UIButton *alertBtn = [UIButton buttonWithType:U ...

  9. iOS 8.0后使用UIAlertController

    iOS 8的新特性之一就是让接口更有适应性.更灵活,因此许多视图控制器的实现方式发生了巨大的变化.全新的UIPresentationController在实现视图控制器间的过渡动画效果和自适应设备尺寸 ...

随机推荐

  1. 开坑Java编写Json解析器,简明教程

    https://zhuanlan.zhihu.com/p/22460835?refer=json-tutorial 课程不是我原创,我打算照他的这个C版本来重写一遍Java的,打算用面向对象的方式来编 ...

  2. 对应sslocal的简易luci web界面

    直接通过官方ss代码库安装的ss, 只有一个可执行的sslocal, 也没找到对应的luci-app, 所以就自己写了一个. 因为/etc/init.d/sslocal 和 /etc/config/s ...

  3. 极路由2(极贰)在OpenWrt下定制自己的ss服务

    默认刷入的OpenWrt带的ss, 只有ss-redir服务, 但是在实际使用中, 很多时候还是希望访问直接通过正常网关, 只有少部分访问需要通过ss, 所以希望能配置成为ss-local服务. 在保 ...

  4. Linux系统下输出某进程内存占用信息的c程序实现

    在实际工作中有时需要程序打印出某个进程的内存占用情况以作参考, 下面介绍一种通过Linux下的伪文件系统/proc 计算某进程内存占用的程序实现方法. 首先, 为什么会有所谓的 伪文件 呢. Linu ...

  5. Lua的string和string库总结

    Lua有7种数据类型,分别是nil.boolean.number.string.table.function.userdata.这里我总结一下Lua的string类型和string库,复习一下,以便加 ...

  6. 《虚拟伙伴》AR增强现实应用开发总结

    一.概述 1.1选题背景 随着时代的发展,人们的生活节奏越来越快,生活质量也越来越高,但却在繁忙之中忽略或者忘记了关心自己成长时代最重要或者最正确的事情和道理.虽然现在有很多社交平台,如微博,微信,f ...

  7. 数塔取数 基础dp

    从低端向上,每个结点取下一层左右结点最大值和本身价值相加,dp[0][0]为最后结果 #include<iostream> #include<algorithm> #inclu ...

  8. android studio 不能创建或者安装模拟器

    解决方法: (1).对与这类问题实在不行卸载然后安装,看看自己的网络是否把android studio下载的东西给墙了,墙了记得换网. (2).我安装andriod studio 2.2.2.0 版本 ...

  9. webpack构建vue项目(配置篇)

    最近公司要求用vue重构项目,还涉及到模块化开发,于是乎,我专门花了几天的时间研究了一下webpack这个目前来看比较热门的模块加载兼打包工具,发现上手并不是很容易,现将总结的一些有关配置的心得分享出 ...

  10. Django进阶(二)

    Template 之前的好多HTML文件中都包含类似"{{ }}"."{% %}",其实他们都是模板语言,模板本质上是HTML,但是夹杂了一些变量和标签,可以方 ...