ios object-c 弹框功能
1、BaseViewController中
BaseViewController.h
@interface BaseViewController : UIViewController
@end
@interface BaseViewController (Alert)
/**
系统弹窗双选项
@param title 标题
@param message 文本内容
@param ok 确定
@param cancle 取消
@param OK 确定按钮回调
*/
- (void)alertTitle:(NSString *)title andMessage:(NSString *)message andOK:(NSString*)ok andCancle:(NSString*)cancle andBlock:(void (^)(UIAlertAction *action))OK;
/**
系统弹窗单选项
@param title 标题
@param message 具体信息
@param handler 回调
*/
- (void)alertTitle:(NSString*)title andMessage:(NSString*)message andCancleBlock:(void (^ __nullable)(UIAlertAction *action))handler;
/**
系统弹窗双选回调
@param title 标题
@param message 内容
@param ok ok
@param cancle cancle
@param OK ok回调
@param cancleBlock 取消回调
*/
- (void)alertTitle:(NSString *)title andMessage:(NSString *)message andOK:(NSString*)ok andCancle:(NSString*)cancle andBlock:(void (^)(UIAlertAction *action))OK andCancleBlock:(void (^)(UIAlertAction *action))cancleBlock;
@end
BaseViewController.m
@interface BaseViewController ()
@end
@implementation BaseViewController
@end
@implementation BaseViewController (Alert)
- (void)alertTitle:(NSString *)title andMessage:(NSString *)message andCancleBlock:(void (^ __nullable)(UIAlertAction *action))handler
{
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:handler];
[alertController addAction:okAction];
[self presentViewController:alertController animated:YES completion:nil];
}
- (void)alertTitle:(NSString *)title andMessage:(NSString *)message andOK:(NSString*)ok andCancle:(NSString*)cancle andBlock:(void (^)(UIAlertAction *action))OK
{
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *okAction = [UIAlertAction actionWithTitle:ok style:UIAlertActionStyleDestructive handler:OK];
[alertController addAction:okAction];
UIAlertAction *cancleAction = [UIAlertAction actionWithTitle:cancle style:UIAlertActionStyleDefault handler:nil];
[alertController addAction:cancleAction];
[self presentViewController:alertController animated:YES completion:nil];
}
- (void)alertTitle:(NSString *)title andMessage:(NSString *)message andOK:(NSString*)ok andCancle:(NSString*)cancle andBlock:(void (^)(UIAlertAction *action))OK andCancleBlock:(void (^)(UIAlertAction *action))cancleBlock
{
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *okAction = [UIAlertAction actionWithTitle:ok style:UIAlertActionStyleDestructive handler:OK];
[alertController addAction:okAction];
UIAlertAction *cancleAction = [UIAlertAction actionWithTitle:cancle style:UIAlertActionStyleDefault handler:cancleBlock];
[alertController addAction:cancleAction];
[self presentViewController:alertController animated:YES completion:nil];
}
@end
2、使用弹框
#import "BaseViewController.h"
@interface MineController : BaseViewController
@end
#import "MineController.h"
@interface MineController ()
@end
@implementation MineController
- (IBAction)deleteButton:(id)sender {
@weakify(self);
[self alertTitle:@"确定删除" andMessage:@"" andOK:@"确定" andCancle:@"取消" andBlock:^(UIAlertAction * _Nonnull action) {
@strongify(self);
}];
}
@end