UIAlertController弹框的使用虽然不复杂,但是代码有点多,如果项目中频繁使用UIAlertController弹框的话会显得代码很累赘。
UIAlertController *alert = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert];
[alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
}]];
[alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
}]];
// 弹出对话框
[object presentViewController:alert animated:true completion:nil];
下面创建一个类用来统一处理弹窗,将需要实现的方法与对象通过参数的形式传递进来。
HYAlertManager.h文件
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
@interface HYAlertManager : NSObject
+(instancetype)shareManager;
-(void)alertTitle:(NSString *)title message:(NSString *