zoukankan      html  css  js  c++  java
  • 由UIAlertController封装的工具类

    由于苹果弃用了之前的AlertView,取而代之的是UIAlertController,但UIAlertController写起来代码量却增多了,加之项目中用到提示的地方很多,写起来很麻烦,于是,封装了一个UIAlertController的工具。

    #import <Foundation/Foundation.h>
    
    @interface AlertControllerTool : NSObject
    
    //没有取消按钮(确认后无跳转)
    +(UIAlertController *)alertMesasge:(NSString *)message  confirmHandler:(void(^)(UIAlertAction *))confirmActionHandle viewController:(UIViewController *)vc;
    
    //没有取消按钮(确认后有跳转)
    +(UIAlertController *)alertTitle:(NSString *)title mesasge:(NSString *)message preferredStyle:(UIAlertControllerStyle *)preferredStyle  confirmHandler:(void(^)(UIAlertAction *))confirmActionHandler viewController:(UIViewController *)vc;
    
    //有取消按钮的
    +(UIAlertController *)alertTitle:(NSString *)title mesasge:(NSString *)message preferredStyle:(UIAlertControllerStyle *)preferredStyle  confirmHandler:(void(^)(UIAlertAction *))confirmHandler cancleHandler:(void(^)(UIAlertAction *))cancleHandler viewController:(UIViewController *)vc;
    
    @end

    方法的实现

    //没有取消按钮的
    +(UIAlertController *)alertMesasge:(NSString *)message  confirmHandler:(void(^)(UIAlertAction *))confirmActionHandle viewController:(UIViewController *)vc
    {
    
         UIAlertController *alertController=[UIAlertController alertControllerWithTitle:@"温馨提示" message:message preferredStyle:UIAlertControllerStyleAlert];
        
        UIAlertAction *confirmAction=[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:confirmActionHandle];
        
        [alertController addAction:confirmAction];
        
        [vc presentViewController:alertController animated:YES completion:nil];
        
        return alertController;
        
    }
    
    //没有取消按钮(确认后有跳转)
    +(UIAlertController *)alertTitle:(NSString *)title mesasge:(NSString *)message preferredStyle:(UIAlertControllerStyle *)preferredStyle  confirmHandler:(void(^)(UIAlertAction *))confirmActionHandler viewController:(UIViewController *)vc
    {
    
        UIAlertController *alertController=[UIAlertController alertControllerWithTitle:title message:message preferredStyle:*preferredStyle];
        
        UIAlertAction *confirmAction=[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:confirmActionHandler];
        
        [alertController addAction:confirmAction];
        
        [vc presentViewController:alertController animated:YES completion:nil];
        
        return alertController;
    
    }
    
    
    //有取消按钮的
    +(UIAlertController *)alertTitle:(NSString *)title mesasge:(NSString *)message preferredStyle:(UIAlertControllerStyle *)preferredStyle  confirmHandler:(void(^)(UIAlertAction *))confirmHandler cancleHandler:(void(^)(UIAlertAction *))cancleHandler viewController:(UIViewController *)vc
    {
    
        UIAlertController *alertController=[UIAlertController alertControllerWithTitle:title message:message preferredStyle:*preferredStyle];
         
        UIAlertAction *confirmAction=[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:confirmHandler];
        
        UIAlertAction *cancleAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:cancleHandler];
        
        [alertController addAction:confirmAction];
        [alertController addAction:cancleAction];
        
        [vc presentViewController:alertController animated:YES completion:nil];
        
        return alertController;
    
    }

    工具的使用

    [AlertControllerTool alertMesasge:@"密码不一致,请重新输入" confirmHandler:nil viewController:self];
    一个人,一片天,一条路,一瞬间!
  • 相关阅读:
    luogu P1630 求和(枚举暴力)
    luogu P3414 SAC#1
    luogu P1869 愚蠢的组合数(质因数+瞎搞)
    luogu P1586 四方定理(背包)
    luogu P3795 钟氏映射(递推)
    2017.8.15 [Haoi2016]字符合并 区间dp+状压dp
    [NOI2002] 荒岛野人 扩展欧几里得算法
    [Noi2002]Savage 扩展欧几里得
    bzoj 1778: [Usaco2010 Hol]Dotp 驱逐猪猡
    bzoj 3505: [Cqoi2014]数三角形
  • 原文地址:https://www.cnblogs.com/zcl410/p/5082500.html
Copyright © 2011-2022 走看看