UIAlertController
2016-01-11 12:54
537 查看
1.创建 UIAlertController *alert =[UIAlertController alertControllerWithTitle: @“警告" message:@"出错了!" preferredStyle:
UIAlertControllerStyleAlert]; 2.添加textField [alert addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField){
// 设置TextField的属性 textField.placeholder = @"倪灏"; // 实时监控textField的内容 [[NSNotificationCenter defaultCenter] addObserver:self selector: @selector(changeAlertValue:) name: UITextFieldTextDidChangeNotificationobject:textField]; }]; 3. 添加按钮 // 创建按钮 UIAlertAction *action = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { // 点击获取textField里的内容 UITextField *textField = [alert.textFields firstObject]; NSLog(@"textField :%@",textField.text); }]; // 添加按钮 [alert addAction:action]; // 设置按钮不可点击 action.enabled = NO; // 显示AlertController [self presentViewController:alert animated:YES completion:^{}]; 4.实现实时监控TextField内容的方法 - (void)changeAlertValue:(NSNotification *)notification{ // 找到AlertController UIAlertController *alert = (UIAlertController *) self.presentedViewController; // 找到TextField UITextField *textField = [alert.textFields firstObject]; // 找到按钮 UIAlertAction *action = [alert.actions firstObject]; // 长度大于4时设置按钮可点击 action.enabled = textField.text.length > 4; }
相关文章推荐
- Arduino建立自己的工程 添加头文件 添加源文件
- SQL Server 阻止了对组件“Ad Hoc Distributed Queries”的 STATEMENT“OpenRowset/OpenDatasource”的访问
- Chapter9-2.Interrupts 《ARM system developer's guide》
- mui h5 动态实现数据的移除和数据操作完后的重新获取
- NGUI的UILabel
- Eigen vector and eigen value
- UIImage拉伸
- mui H5 js动态添加不同类型的数据
- MySQL缓存Query Cache 及优化方法
- 使用Autolayout实现UITableView的Cell动态布局和高度的动态改变
- IOS改变UISearchBar中搜索框的高度
- Amaze UI——slider的参数说明
- UIImage 模糊处理(毛玻璃)
- iOS开发自定义UITabBar实现
- java- Null value was assigned to a property of primitive type setter of
- UICollectionView 简单使用详解
- VS2005为什么有些解决方案不能Build/Rebuild,显示Skipped Build/Rebuild All: Project:xxx
- 利用VUE框架,实现列表分页功能
- 开源免费哈希值校验工具Quickhash V2.6.5
- KBUILD系统原理分析