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
到此这篇苹果手机出现object object_objectc的文章就介绍到这了,更多相关内容请继续浏览下面的相关推荐文章,希望大家都能在编程的领域有一番成就!
版权声明:
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如若内容造成侵权、违法违规、事实不符,请将相关资料发送至xkadmin@xkablog.com进行投诉反馈,一经查实,立即处理!
转载请注明出处,原文链接:https://www.xkablog.com/cjjbc/2096.html