[x-Code7新功能之二]UIAlertController的练习

@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

你可能感兴趣的:([x-Code7新功能之二]UIAlertController的练习)