封装一个UIAlertController
来源:互联网 发布:淘宝客服售后质量话术 编辑:程序博客网 时间:2024/05/22 23:37
UIAlertController写起来比较繁琐, 这里进行一下封装方便使用
你只需要调用该方法即可:
[CommonMethod showAlertControllerTitle:nil msg:@"你真的要退出吗?" superVC:self preferredStyle:(UIAlertControllerStyleAlert) okCallBack:^{ NSLog(@"点击确定回调"); } cancleCallBack:^{ NSLog(@"点击取消 回调"); }];
首先建立一个CommMethod 继承NSObject
.h
#import <Foundation/Foundation.h>#import <UIKit/UIKit.h>@interface CommonMethod : NSObject+ (void)showAlertControllerTitle:(NSString *)title msg:(NSString *)msg superVC:(UIViewController *)superVC preferredStyle:(UIAlertControllerStyle)preferredStyle okCallBack:(void(^)(void))okCallBack cancleCallBack:(void(^)(void))cancleCallBack;@end
.m#import "CommonMethod.h"#import <UIKit/UIKit.h>@implementation CommonMethod+ (void)showAlertControllerTitle:(NSString *)title msg:(NSString *)msg superVC:(UIViewController *)superVC preferredStyle:(UIAlertControllerStyle)preferredStyle okCallBack:(void(^)(void))okCallBack cancleCallBack:(void(^)(void))cancleCallBack { UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title message:msg preferredStyle:preferredStyle]; UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确定" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) { if (okCallBack) { okCallBack(); } }]; UIAlertAction *canAction = [UIAlertAction actionWithTitle:@"取消" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) { if (cancleCallBack) { cancleCallBack(); } }]; [alertController addAction:okAction]; [alertController addAction:canAction]; [superVC presentViewController:alertController animated:YES completion:nil];}@end
在Controller中使用[CommonMethod showAlertControllerTitle:nil msg:@"你真的要退出吗?" superVC:self preferredStyle:(UIAlertControllerStyleAlert) okCallBack:^{ NSLog(@"点击确定回调"); } cancleCallBack:^{ NSLog(@"点击取消 回调"); }];
0 0
- 封装一个UIAlertController
- iOS-一个对UIAlertController的封装类分享
- iOS-UIAlertController简易封装
- iOS - 封装 - UIAlertController
- Swift---UIAlertController封装
- UIAlertController简单封装
- UIAlertController 提示框简单封装
- 基于UIAlertController的封装调用
- UIAlertController的封装,方便使用
- UIAlertView和UIAlertController的封装
- UIAlertController使用的一个坑
- UIAlertController的一个使用误区
- UIAlertController
- UIAlertController
- UIAlertController
- UIAlertController
- UIAlertController
- UIalertController
- mongoDB 查询命令
- git的公钥和私钥
- JVM总结-垃圾回收
- 一个web项目web.xml的配置中<context-param>配置作用
- 下载jenkins比较快的网站
- 封装一个UIAlertController
- Git命令大全
- 【一步步学OpenGL 23】 -《阴影贴图1》
- STM32 NVIC 中断优先级管理
- 业务流程建模标注(BPMN)详细介绍
- minicom
- Tomcat daemon 脚本管理Tomcat
- iOS 设备的CPU架构(持续更新)
- java中String、StringBuffer、StringBuilder总结