UIAlertController类学习
来源:互联网 发布:android源码的使用 编辑:程序博客网 时间:2024/06/07 17:58
UIAlertController用于替代UIActionSheet 和 UIAlertView。
替代UIActionSheet :
UIAlertController * Alert = [UIAlertController
alertControllerWithTitle:@"Are you sure?" //标题
message:nil //标题下的信息
preferredStyle:UIAlertControllerStyleActionSheet//这里选择ActionSheet风格
];
//新建一个动作
UIAlertAction *noWayAction = [UIAlertAction actionWithTitle:@"No way!" //标题
style:UIAlertActionStyleCancel //动作类型
handler:
^(UIAlertAction *action) { NSLog(@"cancel button pressed");}];
[Alert addAction:noWayAction];//把动作添加到控制器中
//新建一个动作
UIAlertAction *yesAction = [UIAlertAction actionWithTitle:@"Yes,i'm Sure!"
style:UIAlertActionStyleDestructive
handler:nil];
[Alert addAction:yesAction];
[self presentViewController:Alert animated:YES completion:nil];//以动画的方式显示
替代UIAlertView:
NSString *msg = nil;
if(_nameField.text.length >0)
msg = [NSStringstringWithFormat:@"You can breath easy, %@, everthing went OK.",_nameField.text];
else
msg = [NSStringstringWithFormat:@"You can breath easy. everything went OK."];
UIAlertController *Alert1 = [UIAlertControlleralertControllerWithTitle:@"Something was done"
message:msg
preferredStyle:UIAlertControllerStyleAlert//这里选择Alert风格
];
UIAlertAction *OKAction = [UIAlertActionactionWithTitle:@"Phew"style:UIAlertActionStyleDefaulthandler:nil];
[Alert1 addAction:OKAction];
[selfpresentViewController:Alert1animated:YEScompletion:nil];
UIAlertControllerStyle:
typedef enumUIAlertControllerStyle:NSInteger {
UIAlertControllerStyleActionSheet =0,//actionSheet风格
UIAlertControllerStyleAlert//Alert风格
} UIAlertControllerStyle;
UIAlertActionStyle:
typedef enumUIAlertActionStyle:NSInteger {
UIAlertActionStyleDefault =0,//默认
UIAlertActionStyleCancel,//取消
UIAlertActionStyleDestructive//确认
} UIAlertActionStyle;
- UIAlertController类学习
- 学习笔记:UIAlertController
- ios UIAlertController学习
- iOS UIAlertController学习笔记
- IOS8 新增UIAlertController类
- UIAlertController
- UIAlertController
- UIAlertController
- UIAlertController
- UIAlertController
- UIalertController
- UIAlertController
- UIalertController
- UIAlertController
- UIAlertController
- UIAlertController
- UIAlertController
- UIAlertController
- 线程同步之volatile关键字
- 《生命如一泓清水》俞敏洪
- 数据库分库分表(sharding)系列(五) 一种支持自由规划无须数据迁移和修改路由代码的Sharding扩容方案
- 自我收藏的网站
- jQuery插件AjaxFileUpload实现ajax文件上传
- UIAlertController类学习
- Java学习之继承
- CentOS64下安装Oracle11g问题与解决方法
- iOS开发之AVAudioPlayer 音频播放
- Bat文件处理详解
- 实现类似IOS中滑动按钮效果
- linux修改文件所属用户和组
- Java反射机制小结
- 测试相关理解(四)边界值分析实例