(十)UIAlertController

一、创建

    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"新建相册"
                                                                             message:@"请输入相册名称"
                                                                      preferredStyle:UIAlertControllerStyleAlert];
    
    [alertController addTextFieldWithConfigurationHandler:^(UITextField *textField){
       textField.placeholder=@"新相册名称";
    }];
    [alertController addTextFieldWithConfigurationHandler:^(UITextField *textField){
        textField.placeholder=@"新相册名称1";
    }];
    [alertController addTextFieldWithConfigurationHandler:^(UITextField *textField){
        textField.placeholder=@"新相册名称2";
    }];
    
    //添加取消到UIAlertController中
    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:nil];
    [alertController addAction:cancelAction];
    
    //添加确定到UIAlertController中
    UIAlertAction *OKAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
        NSString *str1=alertController.textFields.firstObject.text;
        NSEnumerator *enumerator=alertController.textFields.objectEnumerator;   //获取第一个输入框的内容
        NSLog(@"%@",str1);
        
        for (UITextField *object in enumerator) {
            NSLog(@"%@", object.text);  //输出每次的内容
        }
    }];
    [alertController addAction:OKAction];
    
    [self presentViewController:alertController animated:YES completion:nil];

 

posted @ 2017-01-09 18:00  贾辰  阅读(133)  评论(0)    收藏  举报