美文网首页
iOS AlertController的简单封装

iOS AlertController的简单封装

作者: 也远 | 来源:发表于2017-08-01 14:34 被阅读17次

import <UIKit/UIKit.h>

@interface LoginViewController : UIViewController

@end

+(UIAlertController *)showWithInfo:(NSString *)title and:(NSString *)message;

import "YDAlert.h"

@implementation YDAlert

+(UIAlertController *)showWithInfo:(NSString *)title and:(NSString *)message{

UIAlertController * alert = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert];

UIAlertAction *actionOk = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil];

[alert addAction:actionOk];

[[YDAlert currentViewController] presentViewController:alert animated:NO completion:^{
    
}];

return alert;

}

  • (UIViewController *)currentViewController {
    UIWindow *window = [[UIApplication sharedApplication].delegate window];
    UIViewController *presentedVC = [[window rootViewController] presentedViewController];
    if (presentedVC) {
    return presentedVC;

    } else {
    return window.rootViewController;
    }
    }

一句代码调用
[YDAlert showWithInfo:@"账号和密码不能为空" and:@"请输入账号密码"];

相关文章

网友评论

      本文标题:iOS AlertController的简单封装

      本文链接:https://www.haomeiwen.com/subject/vdujlxtx.html