如何为UIAlertViewController定义宏?

时间:2016-03-30 09:14:49

标签: ios objective-c cocoa-touch ios8

我们在旧项目中需要添加400个Alertview对象,因此我想在{8.0}中引入的macro中为UIAlertViewController定义objective-c

请帮我在Constant文件中定义它。

1 个答案:

答案 0 :(得分:-1)

仅适用于Alertview

#define SHOW_ALERT(title,msg,del,cancel,other) \
do { \
UIAlertView *_alert = [[UIAlertView alloc] initWithTitle:title message:msg delegate:del cancelButtonTitle:cancel otherButtonTitles:other,nil]; \
[_alert show]; \
} while(0);

仅适用于AlertViewController

#define SHOW_ALERT2(title,msg,ButtonTitle)\
do { \
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title message:msg preferredStyle:UIAlertControllerStyleAlert];\
    UIAlertAction *actionOk = [UIAlertAction actionWithTitle:ButtonTitle\
                                                       style:UIAlertActionStyleDefault\
                                                     handler:nil]; \
    [alertController addAction:actionOk];\
    [self presentViewController:alertController animated:YES completion:nil];\
}while(0);

适用于AlertView和AlertViewController

#define SHOW_ALERT3(title,msg,delegate,ButtonTitle) \
    do { \
        if ([UIAlertController class]) {\
            UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title message:msg preferredStyle:UIAlertControllerStyleAlert];\
            UIAlertAction *actionOk = [UIAlertAction actionWithTitle:ButtonTitle\
            style:UIAlertActionStyleDefault\
            handler:nil]; \
            [alertController addAction:actionOk];\
            [self presentViewController:alertController animated:YES completion:nil];\
        }\
        else {\
            UIAlertView *_alert = [[UIAlertView alloc] initWithTitle:title message:msg delegate:delegate cancelButtonTitle:ButtonTitle otherButtonTitles:nil]; \
            [_alert show]; \
        }\
    }while(0);
相关问题