UIAlertViewController的簡(jiǎn)單封裝

初識(shí)OC,對(duì)封裝簡(jiǎn)直一竅不通,只能先從簡(jiǎn)單的控件開(kāi)始學(xué)起,下面是封裝的一個(gè)UIAlertViewController分為三種模式:

.h文件

>////? AlertControllerTool.h//? 測(cè)試篇////? Created by HR on 16/12/13.//? Copyright ? 2016年 dawenkeji. All rights reserved.//#import#import@interface AlertControllerTool : NSObject

//沒(méi)有取消按鈕(確認(rèn)后無(wú)跳轉(zhuǎn))

+ (UIAlertController *)alertMessage:(NSString *)message confirmHandler:(void(^)(UIAlertAction *))confirmActionHandle viewController:(UIViewController *)vc;

//沒(méi)有取消按鈕(確認(rèn)后有跳轉(zhuǎn))

+ (UIAlertController *)alertTitle:(NSString *)title message:(NSString *)message preferredStyle:(UIAlertControllerStyle *)preferredStyle confirmHandler:(void(^)(UIAlertAction *))confirmActionHandle viewController:(UIViewController *)vc;

//有取消按鈕

+ (UIViewController *)alertTitle:(NSString *)title message:(NSString *)message preferredStyle:(UIAlertControllerStyle *)preferredStyle confirmHander:(void(^)(UIAlertAction *))confirmActionHandle cancleHander:(void(^)(UIAlertAction *))cancleActionHandle viewController:(UIViewController *)vc;

@end

.m文件

>//

#import "AlertControllerTool.h"

@implementation AlertControllerTool

//沒(méi)有取消按鈕(確認(rèn)后無(wú)跳轉(zhuǎn))

+ (UIAlertController *)alertMessage:(NSString *)message confirmHandler:(void(^)(UIAlertAction *))confirmActionHandle viewController:(UIViewController *)vc{

UIAlertController *alert = [UIAlertController alertControllerWithTitle:

@"溫馨提示" message:

message preferredStyle:UIAlertControllerStyleAlert];

UIAlertAction *confirmAction = [UIAlertAction actionWithTitle:

@"確定"

style:

UIAlertActionStyleDefault

handler:

confirmActionHandle];

[alert addAction:confirmAction];

[vc presentViewController:alert animated:YES completion:nil];

return alert;

}

9528--0001

//沒(méi)有取消按鈕(確認(rèn)后有跳轉(zhuǎn))

+ (UIAlertController *)alertTitle:(NSString *)title message:(NSString *)message preferredStyle:(UIAlertControllerStyle *)preferredStyle confirmHandler:(void(^)(UIAlertAction *))confirmActionHandle viewController:(UIViewController *)vc{

UIAlertController *alert = [UIAlertController alertControllerWithTitle:

title message:

message preferredStyle:

*preferredStyle];

UIAlertAction *action = [UIAlertAction actionWithTitle:

@"確定" style:UIAlertActionStyleDefault? handler:confirmActionHandle];

[alert addAction:action];

[vc presentViewController:alert animated:YES completion:nil];

return alert;

}

//有取消按鈕

+ (UIViewController *)alertTitle:(NSString *)title message:(NSString *)message preferredStyle:(UIAlertControllerStyle *)preferredStyle confirmHander:(void(^)(UIAlertAction *))confirmActionHandle cancleHander:(void(^)(UIAlertAction *))cancleActionHandle viewController:(UIViewController *)vc{

UIAlertController *alert = [UIAlertController alertControllerWithTitle:

title message:

message preferredStyle:

*preferredStyle];

UIAlertAction *action1 = [UIAlertAction actionWithTitle:@"確定" style:UIAlertActionStyleDefault handler:confirmActionHandle];

UIAlertAction *action2 = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:cancleActionHandle];

[alert addAction:action1];

[alert addAction:action2];

[vc presentViewController:alert animated:YES completion:nil];

return alert;

}

@end

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容