首页 > 其他 > 详细

UIAlertController

时间:2015-11-04 17:38:25      阅读:274      评论:0      收藏:0      [点我收藏+]

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    // Do any additional setup after loading the view, typically from a nib.
}


-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    UIAlertController * alert = [UIAlertController alertControllerWithTitle:@"警告" message:@"一大波僵尸在靠近" preferredStyle:UIAlertControllerStyleAlert];
    
    
    //添加按钮
    __weak typeof(alert) weakAlert = alert;
   [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
       NSLog(@"点击了确定按钮---%@---%@",[weakAlert.textFields.firstObject text],[weakAlert.textFields.lastObject text]);
   }]];
    
   [alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
       NSLog(@"点击了取消按钮");
   }]];
    
    //添加文本框
    [alert addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
        textField.text = @"123";
        
        //监听文本框输入的文字内容
        [textField addTarget:self action:@selector(usernameChange:) forControlEvents:UIControlEventAllEditingEvents];
    }];
    
    [alert addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
        
        textField.secureTextEntry = YES;
        textField.text = @"456";
        
        //监听文本框输入的内容
        [textField addTarget:self action:@selector(passwordChande:) forControlEvents:UIControlEventAllEditingEvents];
    }];
    
     [self presentViewController:alert animated:YES completion:nil];
    
}


-(void)usernameChange:(UITextField *)username
{
    NSLog(@"%@",username.text);
}


-(void)passwordChande:(UITextField *)password
{
    NSLog(@"%@",password.text);
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

UIAlertController

原文:http://www.cnblogs.com/yzjxdz/p/4936335.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!