UIAlertController 输入文本框

来源:互联网 发布:17网广州网络批发市场 编辑:程序博客网 时间:2024/05/20 11:24
//初始化提示框;
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"商品费用" message:nil preferredStyle:UIAlertControllerStyleAlert];
    [alert addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
        textField.placeholder = @"请输入商费,可参考收银小票";
        textField.keyboardType = UIKeyboardTypeDecimalPad;
    }];
    //添加一个确定按钮 并获取AlertView中的第一个输入框 将其文本赋值给BUTTON的title
    [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        UITextField *envirnmentNameTextField = alert.textFields.firstObject;
     
        NSLog(@"你输入的文本======%@",envirnmentNameTextField.text);
        
    }]];
    [alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
    }]];
    //弹出提示框;
    [self presentViewController:alert animated:true completion:nil];