IOS UIAlertControl与UIAlertAction
2016-01-07 14:02
387 查看
在ios8中UIAlertAction以及UIAlertControl替代了原来的UIAlertSheet以及UIAlertView,值得注意的是UIAlertControl继承的事UIViewControl!
因为继承的是UIViewControl所以我们需要使用模态present,将UIViewControl Present出来,并且我们不能直接在Viewdid里面进行编写 在这里我们点击空白进行present
在这里我们可以加入多个UITextField而不是以前最多两个
/* typedef NS_ENUM(NSInteger, UIAlertControllerStyle) { UIAlertControllerStyleActionSheet = 0, UIAlertControllerStyleAlert } NS_ENUM_AVAILABLE_IOS(8_0); */ //在这里我们可以决定我们要用的是原来的AlertView还是AlertSheet //也就是说他们由两个控件变成了一个控件的两个Style alertcontrol = [UIAlertController alertControllerWithTitle:@"title" message:@"message" preferredStyle:UIAlertControllerStyleAlert]; [alertcontrol addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) { textField.placeholder = @"方便了很多"; /* typedef NS_ENUM(NSInteger, UIAlertActionStyle) { UIAlertActionStyleDefault = 0,//默认的风格 UIAlertActionStyleCancel,//取消按钮的风格 UIAlertActionStyleDestructive//警告的风格 } */ UIAlertAction * alert = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) { }]; UIAlertAction * alert2 = [UIAlertAction actionWithTitle:@"取消2" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) { }]; [alertcontrol addAction:alert]; [alertcontrol addAction:alert2];
因为继承的是UIViewControl所以我们需要使用模态present,将UIViewControl Present出来,并且我们不能直接在Viewdid里面进行编写 在这里我们点击空白进行present
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{ [self presentViewController:alertcontrol animated:YES completion:^{ }]; }
在这里我们可以加入多个UITextField而不是以前最多两个
相关文章推荐
- 关于PropertyInfo setvalue()和PropertyInfo getvalue()
- ios开发--UIImage转化成NSData
- iOS中UISearchBar(搜索框)使用总结
- 关于使用百度UEditor富文本编辑器的总结
- UITableView使用
- UITableView 属性集合
- iOS下 UILabel 如何自动换行
- 处理二值查询 Processing Boolean queries
- 3.UIImageView基本使用
- 如何实现一个搜索引擎(2):查询索引 How to Implement a Search Engine Part 2: Query Index
- 【转载】GUID vs INT Debate
- 2.UILabel的基本使用
- Java源码-AbstractStringBuilder
- UITableView中复用cell显示信息错乱
- NSInteger 与 NSUInteger 和 int与 NSInteger 区别
- 基于Elasticsearch+Fluentd+Kibana的日志收集分析系统搭建与应用
- UICollectionView
- django实现用户登陆访问限制@login_required
- 1.大神班 UI 526
- 设计模式Builder模式