簡單好用的AlertViewController

發(fā)現(xiàn)一個有趣的郎笆,打開這個DEMO的時候,偶然發(fā)現(xiàn)這個DEMO還是自己在2016年的時候?qū)懙募嗌簟H缃襁€在繼續(xù)使用旅赢,不得不說,那種由代碼產(chǎn)生的喜悅 感惑惶,一下涌上心頭煮盼。
簡單的系統(tǒng)alertViewController的封裝。原有的基礎(chǔ)上增加了新API带污。有需要高級效果的僵控,這個文章可以略過了。有興趣可點(diǎn)個贊刮刑。
雖然東西比較簡單喉祭,還是整理下吧养渴。廢話不多說,直接上代碼。

.h

//
//  KJCommonUI.h
//  KJFrameworkProject
//
//  Created by 王振 DemoKing on 2016/11/15.
//  Copyright ? 2016年 DemoKing. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>

/// KJCommonUI
@interface KJCommonUI : NSObject
#pragma mark -
#pragma mark - 關(guān)于系統(tǒng)彈框

+ (KJCommonUI *)sharedManager;
- (void)hiddenMyAlertController;
/**
 彈框 UIAlertViewController 取消 + 確定 alert window彈出

 @param message 提示語 確定
 */
+ (UIAlertController *)showAlertViewWithSureMessage:(NSString *)message;
/**
 彈框 UIAlertViewController 取消 + 確定 alert window彈出

 @param message 提示語 OK
 */
+ (UIAlertController *)showAlertViewWithOKMessage:(NSString *)message;
/**
 彈框 UIAlertViewController 取消 + 確定 alert window彈出

 @param message 提示語 知道了
 */
+ (UIAlertController *)showAlertViewWithKnowMessage:(NSString *)message;
/**
 彈框 UIAlertViewController 取消 + 確定 alert window彈出

 @param title 提示語 確定
 */
+ (UIAlertController *)showAlertViewWithSureTitle:(NSString *)title;
/**
 彈框 UIAlertViewController 取消 + 確定 alert window彈出

 @param title 提示語 OK
 */
+ (UIAlertController *)showAlertViewWithOKTitle:(NSString *)title;
/**
 彈框 UIAlertViewController 取消 + 確定 alert window彈出

 @param title 提示語 知道了
 */
+ (UIAlertController *)showAlertViewWithKnowTitle:(NSString *)title;
/**
 彈框 UIAlertViewController 取消 + 確定 alert window彈出

 @param title 提示語
 @param cancelButtonTitle 取消按鈕
 */
+ (UIAlertController *)showAlertViewWithTitle:(NSString *)title
                            cancelButtonTitle:(NSString *)cancelButtonTitle;
/**
 彈框 UIAlertViewController 取消 + 確定 alert window彈出

 @param message 提示語
 @param cancelButtonTitle 取消按鈕
 */
+ (UIAlertController *)showAlertViewWithMessage:(NSString *)message
                              cancelButtonTitle:(NSString *)cancelButtonTitle;
/**
 彈框 UIAlertViewController 取消 + 確定 alert window彈出

 @param message 提示語
 @param cancelButtonTitle 取消按鈕
 @param cancelBlock 取消回調(diào)
 */
+ (UIAlertController *)showAlertViewWithMessage:(NSString *)message
                              cancelButtonTitle:(NSString *)cancelButtonTitle
                                    cancelBlock:(void(^)(void))cancelBlock;
/**
 彈框 UIAlertViewController 取消 + 確定 alert window彈出

 @param title 標(biāo)題
 @param cancelButtonTitle 取消按鈕
 @param cancelBlock 取消回調(diào)
 */
+ (UIAlertController *)showAlertViewWithTitle:(NSString *)title
                            cancelButtonTitle:(NSString *)cancelButtonTitle
                                  cancelBlock:(void(^)(void))cancelBlock;
/**
 彈框 UIAlertViewController 取消 + 確定 alert window彈出

 @param title 標(biāo)題
 @param message 提示語
 @param cancelButtonTitle 取消按鈕
 @param cancelBlock 取消回調(diào)
 */
+ (UIAlertController *)showAlertViewWithTitle:(NSString *)title
                                      message:(NSString *)message
                            cancelButtonTitle:(NSString *)cancelButtonTitle
                                  cancelBlock:(void(^)(void))cancelBlock;
/**
 彈框 UIAlertViewController 取消 + 確定 alert

 @param title 標(biāo)題
 @param message 提示語
 @param cancelButtonTitle 取消按鈕
 @param sureButtonTitle 確定按鈕
 @param viewController 視圖控制器
 @param cancelBlock 取消回調(diào)
 @param sureBlock 確定回調(diào)
 */
+ (UIAlertController *)showAlertViewWithTitle:(NSString *)title
                       message:(NSString *)message
             cancelButtonTitle:(NSString *)cancelButtonTitle
               sureButtonTitle:(NSString *)sureButtonTitle
              inViewController:(id)viewController
                   cancelBlock:(void(^)(void))cancelBlock
                     sureBlock:(void(^)(void))sureBlock;
/**
 彈框 UIAlertViewController sheet

 @param titleArray 按鈕標(biāo)題數(shù)組
 @param sureBlock 確定回調(diào)
 */
+ (UIAlertController *)showSheetViewWithTitleArray:(NSArray <NSString *>*)titleArray
                                         sureBlock:(void(^)(UIAlertAction *action))sureBlock;

/**
 彈框 UIAlertViewController sheet

 @param cancelButtonTitle 取消按鈕
 @param titleArray 按鈕標(biāo)題數(shù)組
 @param sureBlock 確定回調(diào)
 */
+ (UIAlertController *)showSheetViewWithCancelButtonTitle:(NSString *)cancelButtonTitle
                                               titleArray:(NSArray <NSString *>*)titleArray
                                                sureBlock:(void(^)(UIAlertAction *action))sureBlock;
/**
 彈框 UIAlertViewController sheet

 @param title 標(biāo)題
 @param message 提示語
 @param cancelButtonTitle 取消按鈕
 @param titleArray 按鈕標(biāo)題數(shù)組
 @param viewController 視圖控制器
 @param sureBlock 確定回調(diào)
 */
+ (UIAlertController *)showSheetViewWithTitle:(NSString *)title
                       message:(NSString *)message
             cancelButtonTitle:(NSString *)cancelButtonTitle
               titleArray:(NSArray <NSString *>*)titleArray
              inViewController:(id)viewController
                     sureBlock:(void(^)(UIAlertAction *action))sureBlock;
/**
 彈框 UIAlertViewController sheet

 @param title 標(biāo)題
 @param message 提示語
 @param cancelButtonTitle 取消按鈕
 @param titleArray 按鈕標(biāo)題數(shù)組
 @param viewController 視圖控制器
 @param cancelBlock 取消回調(diào)
 @param sureBlock 確定回調(diào)
 */
+ (UIAlertController *)showSheetViewWithTitle:(NSString *)title
                       message:(NSString *)message
             cancelButtonTitle:(NSString *)cancelButtonTitle
               titleArray:(NSArray <NSString *>*)titleArray
              inViewController:(id)viewController
                   cancelBlock:(void(^)(void))cancelBlock
                     sureBlock:(void(^)(UIAlertAction *action))sureBlock;
/**
 彈框 UIAlertViewController 取消 + 確定 alert
 
 @param title 標(biāo)題
 @param message 提示語
 @param cancelButtonTitle 取消按鈕
 @param sureButtonTitle 確定按鈕
 @param placeholder placeholder
 @param viewController 視圖控制器
 @param cancelBlock 取消回調(diào)
 @param sureBlock 確定回調(diào)
 */
+ (UIAlertController *)showSingleTextFieldAlertViewWithTitle:(NSString *)title
                                                     message:(NSString *)message
                                           cancelButtonTitle:(NSString *)cancelButtonTitle
                                             sureButtonTitle:(NSString *)sureButtonTitle
                                                 placeholder:(NSString *)placeholder
                                            inViewController:(id)viewController
                                                 cancelBlock:(void(^)(void))cancelBlock
                                                   sureBlock:(void(^)(UITextField *textFeild))sureBlock;
@end

.m

//
//  KJCommonUI.m
//  KJFrameworkProject
//
//  Created by DEMOKING on 2016/11/15.
//  Copyright ? 2016年 DEMOKING. All rights reserved.
//

#import "KJCommonUI.h"
@interface KJCommonUI ()

@property (strong, nonatomic) UIAlertController *controller;

@end
@implementation KJCommonUI

+ (KJCommonUI *)sharedManager {
    static KJCommonUI *sharedManager = nil;
    static dispatch_once_t predicate;
    dispatch_once(&predicate, ^{
        sharedManager = [[KJCommonUI alloc] init];
    });
    return sharedManager;
}

- (void)hiddenMyAlertController {
    if (self.controller) {
        [self.controller dismissViewControllerAnimated:NO completion:nil];
    }
}
/**
 彈框 UIAlertViewController 取消 + 確定 alert window彈出

 @param message 提示語 確定
 */
+ (UIAlertController *)showAlertViewWithSureMessage:(NSString *)message {
    UIWindow *window = [UIApplication sharedApplication].keyWindow;
    UIAlertController *viewController = [KJCommonUI showAlertViewWithTitle:nil
                                                                   message:message
                                                         cancelButtonTitle:@"確定"
                                                           sureButtonTitle:nil
                                                          inViewController:window.rootViewController
                                                               cancelBlock:nil
                                                                 sureBlock:nil];
    return viewController;
}
/**
 彈框 UIAlertViewController 取消 + 確定 alert window彈出

 @param message 提示語 OK
 */
+ (UIAlertController *)showAlertViewWithOKMessage:(NSString *)message {
    UIWindow *window = [UIApplication sharedApplication].keyWindow;
    UIAlertController *viewController = [KJCommonUI showAlertViewWithTitle:nil
                                                                   message:message
                                                         cancelButtonTitle:@"OK"
                                                           sureButtonTitle:nil
                                                          inViewController:window.rootViewController
                                                               cancelBlock:nil
                                                                 sureBlock:nil];
    return viewController;
}
/**
 彈框 UIAlertViewController 取消 + 確定 alert window彈出

 @param message 提示語 知道了
 */
+ (UIAlertController *)showAlertViewWithKnowMessage:(NSString *)message {
    UIWindow *window = [UIApplication sharedApplication].keyWindow;
    UIAlertController *viewController = [KJCommonUI showAlertViewWithTitle:nil
                                                                   message:message
                                                         cancelButtonTitle:@"知道了"
                                                           sureButtonTitle:nil
                                                          inViewController:window.rootViewController
                                                               cancelBlock:nil
                                                                 sureBlock:nil];
    return viewController;
}
/**
 彈框 UIAlertViewController 取消 + 確定 alert window彈出

 @param title 提示語 確定
 */
+ (UIAlertController *)showAlertViewWithSureTitle:(NSString *)title {
    UIWindow *window = [UIApplication sharedApplication].keyWindow;
    UIAlertController *viewController = [KJCommonUI showAlertViewWithTitle:title
                                                                   message:nil
                                                         cancelButtonTitle:@"確定"
                                                           sureButtonTitle:nil
                                                          inViewController:window.rootViewController
                                                               cancelBlock:nil
                                                                 sureBlock:nil];
    return viewController;
}
/**
 彈框 UIAlertViewController 取消 + 確定 alert window彈出

 @param title 提示語 OK
 */
+ (UIAlertController *)showAlertViewWithOKTitle:(NSString *)title {
    UIWindow *window = [UIApplication sharedApplication].keyWindow;
    UIAlertController *viewController = [KJCommonUI showAlertViewWithTitle:title
                                                                   message:nil
                                                         cancelButtonTitle:@"OK"
                                                           sureButtonTitle:nil
                                                          inViewController:window.rootViewController
                                                               cancelBlock:nil
                                                                 sureBlock:nil];
    return viewController;
}
/**
 彈框 UIAlertViewController 取消 + 確定 alert window彈出

 @param title 提示語 知道了
 */
+ (UIAlertController *)showAlertViewWithKnowTitle:(NSString *)title {
    UIWindow *window = [UIApplication sharedApplication].keyWindow;
    UIAlertController *viewController = [KJCommonUI showAlertViewWithTitle:title
                                                                   message:nil
                                                         cancelButtonTitle:@"知道了"
                                                           sureButtonTitle:nil
                                                          inViewController:window.rootViewController
                                                               cancelBlock:nil
                                                                 sureBlock:nil];
    return viewController;
}
/**
 彈框 UIAlertViewController 取消 + 確定 alert window彈出

 @param title 提示語
 @param cancelButtonTitle 取消按鈕
 */
+ (UIAlertController *)showAlertViewWithTitle:(NSString *)title
                            cancelButtonTitle:(NSString *)cancelButtonTitle {
    UIWindow *window = [UIApplication sharedApplication].keyWindow;
    UIAlertController *viewController = [KJCommonUI showAlertViewWithTitle:title
                                                                   message:nil
                                                         cancelButtonTitle:cancelButtonTitle
                                                           sureButtonTitle:nil
                                                          inViewController:window.rootViewController
                                                               cancelBlock:nil
                                                                 sureBlock:nil];
    return viewController;
}
/**
 彈框 UIAlertViewController 取消 + 確定 alert window彈出

 @param message 提示語
 @param cancelButtonTitle 取消按鈕
 */
+ (UIAlertController *)showAlertViewWithMessage:(NSString *)message
                              cancelButtonTitle:(NSString *)cancelButtonTitle {
    UIWindow *window = [UIApplication sharedApplication].keyWindow;
    UIAlertController *viewController = [KJCommonUI showAlertViewWithTitle:nil
                                                                   message:message
                                                         cancelButtonTitle:cancelButtonTitle
                                                           sureButtonTitle:nil
                                                          inViewController:window.rootViewController
                                                               cancelBlock:nil
                                                                 sureBlock:nil];
    return viewController;
}
/**
 彈框 UIAlertViewController 取消 + 確定 alert window彈出

 @param message 提示語
 @param cancelButtonTitle 取消按鈕
 @param cancelBlock 取消回調(diào)
 */
+ (UIAlertController *)showAlertViewWithMessage:(NSString *)message
                              cancelButtonTitle:(NSString *)cancelButtonTitle
                                    cancelBlock:(void(^)(void))cancelBlock {
    UIWindow *window = [UIApplication sharedApplication].keyWindow;
    UIAlertController *viewController = [KJCommonUI showAlertViewWithTitle:nil
                                                                   message:message
                                                         cancelButtonTitle:cancelButtonTitle
                                                           sureButtonTitle:nil
                                                          inViewController:window.rootViewController
                                                               cancelBlock:cancelBlock
                                                                 sureBlock:nil];
    return viewController;
}
/**
 彈框 UIAlertViewController 取消 + 確定 alert window彈出

 @param title 標(biāo)題
 @param cancelButtonTitle 取消按鈕
 @param cancelBlock 取消回調(diào)
 */
+ (UIAlertController *)showAlertViewWithTitle:(NSString *)title
                            cancelButtonTitle:(NSString *)cancelButtonTitle
                                  cancelBlock:(void(^)(void))cancelBlock {
    UIWindow *window = [UIApplication sharedApplication].keyWindow;
    UIAlertController *viewController = [KJCommonUI showAlertViewWithTitle:title
                                                                   message:nil
                                                         cancelButtonTitle:cancelButtonTitle
                                                           sureButtonTitle:nil
                                                          inViewController:window.rootViewController
                                                               cancelBlock:cancelBlock
                                                                 sureBlock:nil];
    return viewController;
}
/**
 彈框 UIAlertViewController 取消 + 確定 alert window彈出

 @param title 標(biāo)題
 @param message 提示語
 @param cancelButtonTitle 取消按鈕
 @param cancelBlock 取消回調(diào)
 */
+ (UIAlertController *)showAlertViewWithTitle:(NSString *)title
                                      message:(NSString *)message
                            cancelButtonTitle:(NSString *)cancelButtonTitle
                                  cancelBlock:(void(^)(void))cancelBlock {
    UIWindow *window = [UIApplication sharedApplication].keyWindow;
    UIAlertController *viewController = [KJCommonUI showAlertViewWithTitle:title
                                                                   message:message
                                                         cancelButtonTitle:cancelButtonTitle
                                                           sureButtonTitle:nil
                                                          inViewController:window.rootViewController
                                                               cancelBlock:cancelBlock
                                                                 sureBlock:nil];
    return viewController;
}
/**
 彈框 UIAlertViewController
 
 @param title 標(biāo)題
 @param message 提示語
 @param cancelButtonTitle 取消按鈕
 @param sureButtonTitle 確定按鈕
 @param viewController 視圖控制器
 @param cancelBlock 取消回調(diào)
 @param sureBlock 確定回調(diào)
 */
+ (UIAlertController *)showAlertViewWithTitle:(NSString *)title
                       message:(NSString *)message
             cancelButtonTitle:(NSString *)cancelButtonTitle
               sureButtonTitle:(NSString *)sureButtonTitle
              inViewController:(id)viewController
                   cancelBlock:(void(^)(void))cancelBlock
                     sureBlock:(void(^)(void))sureBlock {
    UIAlertController * alertVC = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert];
    if (sureButtonTitle) {
        UIAlertAction * actionSure = [UIAlertAction actionWithTitle:sureButtonTitle style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            [KJCommonUI sharedManager].controller = nil;
            if (sureBlock) {
                sureBlock();
            }
        }];
        [alertVC addAction:actionSure];
    }
    if (cancelButtonTitle.length) {
        UIAlertAction * actionCancel = [UIAlertAction actionWithTitle:cancelButtonTitle style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
            [KJCommonUI sharedManager].controller = nil;
            if (cancelBlock) {
                cancelBlock();
            }
        }];
        [alertVC addAction:actionCancel];
    }
    NSString *deviceType = [UIDevice currentDevice].model;
    if([deviceType isEqualToString:@"iPad"]) {
        alertVC.popoverPresentationController.sourceView = [(UIViewController *)viewController view];
    }
    [viewController presentViewController:alertVC animated:YES completion:nil];
    [KJCommonUI sharedManager].controller = alertVC;
    return alertVC;
}
/**
 彈框 UIAlertViewController sheet

 @param titleArray 按鈕標(biāo)題數(shù)組
 @param sureBlock 確定回調(diào)
 */
+ (UIAlertController *)showSheetViewWithTitleArray:(NSArray <NSString *>*)titleArray
                                         sureBlock:(void(^)(UIAlertAction *action))sureBlock {
    UIWindow *window = [UIApplication sharedApplication].keyWindow;
    UIAlertController *alertViewController = [KJCommonUI showSheetViewWithTitle:nil
                                                                        message:nil
                                                              cancelButtonTitle:@"取消"
                                                                     titleArray:titleArray
                                                               inViewController:window.rootViewController
                                                                    cancelBlock:nil
                                                                      sureBlock:sureBlock];
    return alertViewController;
}

/**
 彈框 UIAlertViewController sheet

 @param cancelButtonTitle 取消按鈕
 @param titleArray 按鈕標(biāo)題數(shù)組
 @param sureBlock 確定回調(diào)
 */
+ (UIAlertController *)showSheetViewWithCancelButtonTitle:(NSString *)cancelButtonTitle
                                               titleArray:(NSArray <NSString *>*)titleArray
                                                sureBlock:(void(^)(UIAlertAction *action))sureBlock {
    UIWindow *window = [UIApplication sharedApplication].keyWindow;
    UIAlertController *alertViewController = [KJCommonUI showSheetViewWithTitle:nil
                                                                        message:nil
                                                              cancelButtonTitle:cancelButtonTitle
                                                                     titleArray:titleArray
                                                               inViewController:window.rootViewController
                                                                    cancelBlock:nil
                                                                      sureBlock:sureBlock];
    return alertViewController;
}
/**
 彈框 UIAlertViewController sheet

 @param title 標(biāo)題
 @param message 提示語
 @param cancelButtonTitle 取消按鈕
 @param titleArray 按鈕標(biāo)題數(shù)組
 @param viewController 視圖控制器
 @param sureBlock 確定回調(diào)
 */
+ (UIAlertController *)showSheetViewWithTitle:(NSString *)title
                                      message:(NSString *)message
                            cancelButtonTitle:(NSString *)cancelButtonTitle
                                   titleArray:(NSArray <NSString *>*)titleArray
                             inViewController:(id)viewController
                                    sureBlock:(void(^)(UIAlertAction *action))sureBlock {
    UIAlertController *alertViewController = [KJCommonUI showSheetViewWithTitle:title
                                                                        message:message
                                                              cancelButtonTitle:cancelButtonTitle
                                                                     titleArray:titleArray
                                                               inViewController:viewController
                                                                    cancelBlock:nil
                                                                      sureBlock:sureBlock];
    return alertViewController;
}
/**
 彈框 UIAlertViewController sheet
 
 @param title 標(biāo)題
 @param message 提示語
 @param cancelButtonTitle 取消按鈕
 @param titleArray 按鈕標(biāo)題數(shù)組
 @param viewController 視圖控制器
 @param cancelBlock 取消回調(diào)
 @param sureBlock 確定回調(diào)
 */
+ (UIAlertController *)showSheetViewWithTitle:(NSString *)title
                       message:(NSString *)message
             cancelButtonTitle:(NSString *)cancelButtonTitle
                    titleArray:(NSArray <NSString *>*)titleArray
              inViewController:(id)viewController
                   cancelBlock:(void(^)(void))cancelBlock
                     sureBlock:(void (^)(UIAlertAction *))sureBlock {
    UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleActionSheet];
    [titleArray enumerateObjectsUsingBlock:^(NSString * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        UIAlertAction * actionSure = [UIAlertAction actionWithTitle:obj style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            [KJCommonUI sharedManager].controller = nil;
            if (sureBlock) {
                sureBlock(action);
            }
        }];
        [alertVC addAction:actionSure];
    }];
    if (cancelButtonTitle) {
        UIAlertAction * actionCancel = [UIAlertAction actionWithTitle:cancelButtonTitle style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
            [KJCommonUI sharedManager].controller = nil;
            if (cancelBlock) {
                cancelBlock();
            }
        }];
        [alertVC addAction:actionCancel];
    }
    NSString *deviceType = [UIDevice currentDevice].model;
    if([deviceType isEqualToString:@"iPad"]) {
        UIPopoverPresentationController * popPresenter = [alertVC popoverPresentationController];
        popPresenter.sourceView = [viewController view];
        CGFloat width = [UIScreen mainScreen].bounds.size.width;
        CGFloat height = [UIScreen mainScreen].bounds.size.height;
        popPresenter.sourceRect = CGRectMake(width / 2 - 152, height, 304, 127.5);
    }
    [viewController presentViewController:alertVC animated:YES completion:nil];
    [KJCommonUI sharedManager].controller = alertVC;
    return alertVC;
}
/**
 彈框 UIAlertViewController 取消 + 確定 alert
 
 @param title 標(biāo)題
 @param message 提示語
 @param cancelButtonTitle 取消按鈕
 @param sureButtonTitle 確定按鈕
 @param placeholder placeholder
 @param viewController 視圖控制器
 @param cancelBlock 取消回調(diào)
 @param sureBlock 確定回調(diào)
 */
+ (UIAlertController *)showSingleTextFieldAlertViewWithTitle:(NSString *)title
                                                     message:(NSString *)message
                                           cancelButtonTitle:(NSString *)cancelButtonTitle
                                             sureButtonTitle:(NSString *)sureButtonTitle
                                                 placeholder:(NSString *)placeholder
                                            inViewController:(id)viewController
                                                 cancelBlock:(void(^)(void))cancelBlock
                                                   sureBlock:(void(^)(UITextField *textFeild))sureBlock {
    UIAlertController* alert = [UIAlertController alertControllerWithTitle:title
                                                                   message:message
                                                            preferredStyle:UIAlertControllerStyleAlert];
    [alert addTextFieldWithConfigurationHandler:^(UITextField *textField) {
        textField.returnKeyType = UIReturnKeyDone;
        textField.placeholder = placeholder;
        textField.delegate = viewController;
    }];
    UIAlertAction* okAction = [UIAlertAction actionWithTitle:sureButtonTitle style:UIAlertActionStyleDefault
                                                     handler:^(UIAlertAction * action) {
                                                         UITextField *text = [alert.textFields firstObject];
        [KJCommonUI sharedManager].controller = nil;
                                                         if (sureBlock) {
                                                             sureBlock(text);
                                                         }
                                                     }];
    UIAlertAction* cancelAction = [UIAlertAction actionWithTitle:cancelButtonTitle style:UIAlertActionStyleCancel
                                                         handler:^(UIAlertAction * action) {
        [KJCommonUI sharedManager].controller = nil;
                                                             if (cancelBlock) {
                                                                 cancelBlock();
                                                             }
                                                         }];
    [alert addAction:okAction];
    [alert addAction:cancelAction];
    [viewController presentViewController:alert animated:YES completion:nil];
    [KJCommonUI sharedManager].controller = alert;
    return alert;
}
@end


注意事項(xiàng)店量,一起來思考幾個問題:

1余佃、適配ipad的問題;

2藐唠、window的獲取問題帆疟;

3、是否需要單例類持有的問題宇立;


V動動手指(woai1101992)點(diǎn)個贊吧X


IMG_0319.JPG
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末踪宠,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子妈嘹,更是在濱河造成了極大的恐慌柳琢,老刑警劉巖,帶你破解...
    沈念sama閱讀 207,113評論 6 481
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件润脸,死亡現(xiàn)場離奇詭異柬脸,居然都是意外死亡,警方通過查閱死者的電腦和手機(jī)毙驯,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 88,644評論 2 381
  • 文/潘曉璐 我一進(jìn)店門倒堕,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人爆价,你說我怎么就攤上這事垦巴∠碧拢” “怎么了?”我有些...
    開封第一講書人閱讀 153,340評論 0 344
  • 文/不壞的土叔 我叫張陵骤宣,是天一觀的道長蛾号。 經(jīng)常有香客問我,道長涯雅,這世上最難降的妖魔是什么鲜结? 我笑而不...
    開封第一講書人閱讀 55,449評論 1 279
  • 正文 為了忘掉前任,我火速辦了婚禮活逆,結(jié)果婚禮上精刷,老公的妹妹穿的比我還像新娘。我一直安慰自己蔗候,他們只是感情好怒允,可當(dāng)我...
    茶點(diǎn)故事閱讀 64,445評論 5 374
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著锈遥,像睡著了一般纫事。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上所灸,一...
    開封第一講書人閱讀 49,166評論 1 284
  • 那天丽惶,我揣著相機(jī)與錄音,去河邊找鬼爬立。 笑死钾唬,一個胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的侠驯。 我是一名探鬼主播抡秆,決...
    沈念sama閱讀 38,442評論 3 401
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼吟策!你這毒婦竟也來了儒士?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 37,105評論 0 261
  • 序言:老撾萬榮一對情侶失蹤檩坚,失蹤者是張志新(化名)和其女友劉穎着撩,沒想到半個月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體效床,經(jīng)...
    沈念sama閱讀 43,601評論 1 300
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡睹酌,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 36,066評論 2 325
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了剩檀。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片憋沿。...
    茶點(diǎn)故事閱讀 38,161評論 1 334
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖沪猴,靈堂內(nèi)的尸體忽然破棺而出辐啄,到底是詐尸還是另有隱情采章,我是刑警寧澤,帶...
    沈念sama閱讀 33,792評論 4 323
  • 正文 年R本政府宣布壶辜,位于F島的核電站悯舟,受9級特大地震影響,放射性物質(zhì)發(fā)生泄漏砸民。R本人自食惡果不足惜抵怎,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 39,351評論 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望岭参。 院中可真熱鬧反惕,春花似錦、人聲如沸演侯。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,352評論 0 19
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽秒际。三九已至悬赏,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間娄徊,已是汗流浹背闽颇。 一陣腳步聲響...
    開封第一講書人閱讀 31,584評論 1 261
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留嵌莉,地道東北人进萄。 一個月前我還...
    沈念sama閱讀 45,618評論 2 355
  • 正文 我出身青樓捻脖,卻偏偏與公主長得像锐峭,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子可婶,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 42,916評論 2 344