使用Alert弹窗案例:
代码:
#import "ViewController.h"
@interface ViewController ()
@property (weak, nonatomic) IBOutlet UITextField *inputName;
@property (weak, nonatomic) IBOutlet UITextField *inputPassword;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (IBAction)loginAction:(UIButton *)sender {
NSString *message = @"";
message = @"登陆成功";
if ([_inputName.text length] < 1) {
message = @"请输入名字";
}
if ([_inputPassword.text length] < 1){
message = @"请输入密码";
}
if ([_inputName.text length] < 6) {
message = @"名字长度不够";
}
if ([_inputPassword.text length] < 6) {
message = @"密码长度不够";
}
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"提示信息"
message:message
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *confirmButton = [UIAlertAction actionWithTitle:@"OK"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * _Nonnull action) {
NSLog(@"OK Action");
}];
UIAlertAction *cancelButton = [UIAlertAction actionWithTitle:@"Cancel"
style:UIAlertActionStyleCancel
handler:^(UIAlertAction * _Nonnull action) {
NSLog(@"Cancel Action");
}];
[alertController addAction:confirmButton];
[alertController addAction:cancelButton];
[self presentViewController:alertController animated:YES completion:nil];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
输出: