ios UIAlertController 添加 textfield

这样的效果

屏幕快照 2017-10-30 14.11.16.png

废话不说,直接贴代码

UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"在线转账" message:balance preferredStyle:UIAlertControllerStyleAlert];
    [alertController addTextFieldWithConfigurationHandler:^(UITextField *textField){
        textField.placeholder = @"请输入电话号码";
        textField.keyboardType = UIKeyboardTypePhonePad;
    }];
    [alertController addTextFieldWithConfigurationHandler:^(UITextField *textField){
        textField.placeholder = @"请输入要转账的金额";
        textField.keyboardType = UIKeyboardTypeDecimalPad;
    }];
    
    UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"好的" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
        UITextField *phone = alertController.textFields.firstObject;
        UITextField *money = [alertController.textFields objectAtIndex:1];
        
        if (phone.text.length != 11) {
            [PublicMethod showAlert:self message:@"请输入格式正确的电话号码"];
        } else if (money.text != nil){
            // 进行你需要d
    }];
    
    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
    
    [alertController addAction:okAction];
    [alertController addAction:cancelAction];
    
    [self presentViewController:alertController animated:YES completion:^{
        
    }];

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 177,123评论 25 709
  • 《王者速读》中一直强调的观念如题,作为阅读者你就是国王,书籍是你的奴仆。 或许太多人像我一样,曾经是一个不爱...
    沙棘1234阅读 1,468评论 0 1
  • 拂袖镜中人,画眉胭脂粉。半面妆容艳,悄然泪满裳。大家好,我是柳上卿。
    云游一片天阅读 1,567评论 0 0
  • 我吃东西的时候有一个习惯,不论开始吃什么,中间上什么,最后吃下的肯定是我相对喜欢的东西,这大概就是俗语说的“吃得苦...
    正解Z阅读 2,812评论 0 1
  • 常用命令缩写 安装 package常规:npm install pkg, 缩写:npm i pkg 安装全局pac...
    1024译站阅读 4,962评论 2 3

友情链接更多精彩内容