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:@"请输入账号密码"];