UIAlerController 优化
来源:互联网 发布:网络会计若干问题探讨 编辑:程序博客网 时间:2024/06/05 16:57
目的就是缩减代码量,将重复代码放在一个类中。
DYAlertController类,如下
.h:
#import <UIKit/UIKit.h>@interface DYAlertController : UIAlertController+(instancetype)DYAlertDefaultMessage:(NSString*)defaultMessage alertTitle:(NSString*)title alertMessage:(NSString*)message perferredStyle:(UIAlertControllerStyle)perferredStyle;-(void)show :(UIViewController*)currVC;@end
.m
#import "DYAlertController.h"@interface DYAlertController ()@end@implementation DYAlertController+(instancetype)DYAlertDefaultMessage:(NSString *)defaultMessage alertTitle:(NSString *)title alertMessage:(NSString *)message perferredStyle:(UIAlertControllerStyle)perferredStyle{ DYAlertController* dyAlertController = [DYAlertController alertControllerWithTitle:title message:message preferredStyle:perferredStyle]; UIAlertAction* defaultAlertAction = [UIAlertAction actionWithTitle:defaultMessage style:UIAlertActionStyleCancel handler:nil]; [dyAlertController addAction:defaultAlertAction]; return dyAlertController;}-(void)show :(UIViewController*)currVC{ if(![currVC isEqual:NULL]) [currVC presentViewController:self animated:YES completion:nil];}@end在viewcontroller使用中:
DYAlertController* alrt = [DYAlertController DYAlertDefaultMessage:@"cancel" alertTitle:@"title" alertMessage:@"message" perferredStyle:UIAlertControllerStyleAlert]; [alrt addAction:[UIAlertAction actionWithTitle:@"去设置" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) { NSLog(@"执行自定义操作,去设置..."); }]]; [alrt show:self];
阅读全文
0 0
- UIAlerController 优化
- UIAlertView更换为UIAlerController
- 优化
- 优化
- 优化
- 优化
- 优化
- 优化
- 优化
- 优化
- 优化
- 优化
- 优化
- 优化
- 优化
- 优化
- 优化
- 优化
- 日历插件和富文本框
- 前端面试知识点总结
- 找出伪币问题
- [日推荐]『TheGolfGame』一个高端大气上档次的小程序
- WPF中DataGrid的应用
- UIAlerController 优化
- Arcgis for Android多版本中文字体乱码解决方案
- 数据的4种存储方式
- Java基础知识第四篇-线程
- 读《暗时间》笔记
- MySQL数据导入异常问题
- H5-localStorage数据存储总结
- 【session】java.lang.IllegalStateException: getAttribute: Session already invalidated
- js 使用前端导出excel,设置标题和页脚,实现特殊表格需求