[x-Code7新功能之二]UIAlertController的练习
2016-04-10 07:55
435 查看
@interface MyPublicFuntions : NSObject +(void)AlertOkAndCancel:(UIViewController* _Nonnull) AController Message:(NSString* _Nonnull) AMessgae OkHandler:(void (^ _Nullable)(UIAlertAction* _Nullable action )) AOkHandler CancleHandler:(void (^ _Nullable)(UIAlertAction* _Nullable action )) ACancelHandler Completion:(NSInteger (^ _Nullable)()) ACompletion; +(void)AlertOkOnly:(UIViewController* _Nonnull) AController Message:(NSString* _Nonnull) AMessgae OkHandler:(void (^ _Nullable)(UIAlertAction* _Nullable action )) AOkHandler Completion:(NSInteger (^ _Nullable)()) ACompletion; +(void)AlertPassWordOnly:(UIViewController* _Nonnull) AController OkHandler:(void (^ _Nullable)(UIAlertAction* _Nullable Action ,NSString* _Nullable APassword)) AOkHandler CancleHandler:(void (^ _Nullable)(UIAlertAction* _Nullable action )) ACancelHandler Completion:(NSInteger (^ _Nullable)()) ACompletion; @end
#import "MyPublicFuntions.h" @implementation MyPublicFuntions +(void)AlertOkAndCancel:(UIViewController* _Nonnull) AController Message:(NSString* _Nonnull) AMessgae OkHandler:(void (^)(UIAlertAction * _Nullable))AOkHandler CancleHandler:(void (^)(UIAlertAction * _Nullable))ACancelHandler Completion:(NSInteger (^)())ACompletion { UIAlertController* AlertController = [UIAlertController alertControllerWithTitle:@"询问框" message:AMessgae preferredStyle:UIAlertControllerStyleAlert]; UIAlertAction* OkAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { if(AOkHandler) AOkHandler(action); }]; UIAlertAction* CancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) { if (ACancelHandler) ACancelHandler(action); }]; [AlertController addAction:OkAction]; [AlertController addAction:CancelAction]; [AController presentViewController:AlertController animated:YES completion:^{ if (ACompletion) ACompletion(); }]; }; +(void)AlertOkOnly:(UIViewController *)AController Message:(NSString *)AMessgae OkHandler:(void (^)(UIAlertAction * _Nullable))AOkHandler Completion:(NSInteger (^)())ACompletion { UIAlertController* AlertController = [UIAlertController alertControllerWithTitle:@"提示框" message:AMessgae preferredStyle:UIAlertControllerStyleAlert]; UIAlertAction* OkAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { if(AOkHandler) AOkHandler(action); }]; [AlertController addAction:OkAction]; [AController presentViewController:AlertController animated:YES completion:^{ if (ACompletion) ACompletion(); }]; } +(void)AlertPassWordOnly:(UIViewController *)AController OkHandler:(void (^)(UIAlertAction * _Nullable, NSString * _Nullable))AOkHandler CancleHandler:(void (^)(UIAlertAction * _Nullable))ACancelHandler Completion:(NSInteger (^)())ACompletion { UIAlertController* AlertController = [UIAlertController alertControllerWithTitle:@"请输入密码" message:nil preferredStyle:UIAlertControllerStyleAlert]; UIAlertAction* OkAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { if(AOkHandler) AOkHandler(action,AlertController.textFields.firstObject.text); }]; UIAlertAction* CancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) { if (ACancelHandler) ACancelHandler(action); }]; [AlertController addAction:OkAction]; [AlertController addAction:CancelAction]; [AlertController addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) { textField.placeholder = @"密码"; textField.secureTextEntry = YES; }]; [AController presentViewController:AlertController animated:YES completion:^{ if (ACompletion) ACompletion(); }]; } @end
相关文章推荐
- map key value的排序问题
- [091127]Dark Blue幽深之蓝【汉化硬盘版】[带全CG存档&攻略+日文原版文件]
- OS开发UI篇—UITabBarController简单介绍
- UI测试
- js模块化之require.js
- UI调试神器 for ios:Reveal的使用与破解
- invalid bundle ipad multitasking support requires launch story board in bundle ...
- required opengl extension,please update your opengl driver
- 用UIButton的类方法ButtonWithType创建时调用的是initWithFrame方法
- 轻量级应用开发之(08)UITableView
- 特殊权限
- druid 数据库密码加密
- 在Android value中添加颜色resource文件
- [BZOJ4430][Nwerc2015]Guessing Camels赌骆驼
- STL学习系列七:优先级队列priority_queue容器
- easyui的datagrid删除一条记录后更新出问题
- 梦想中的图文发布——UEditor使用
- UITableView进阶注意点
- pop push UIViewController 手势过渡动画
- easyui跨iframe属性datagrid