iOS 自己写的对话框中加入三个输入框

时间:2022-09-12 18:48:16

 

-(void)dialog:(NSString*)title okTitle:(NSString*)okTitle placeholder:(NSString*)placeholder finish:(UIAlertControllerSuccess)finish {

    UIAlertController* alert = [UIAlertController alertControllerWithTitle:title message:nil preferredStyle:UIAlertControllerStyleAlert];

    UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:okTitle style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {

//        UITextField* edictTextField = alert.textFields[0];

//        DLOG(@"点击了ok %@", edictTextField.text);

        finish(1, alert.textFields);

    }];

    

    UIAlertAction* cancel = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {

        [alert dismissViewControllerAnimated:YES completion:nil];

        finish(0, alert.textFields);

//        UITextField* edictTextField = alert.textFields[0];

//        DLOG(@"点击了cancel %@", edictTextField.text);

    }];

    

    [alert addAction:defaultAction];

    [alert addAction:cancel];

    [alert addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {

        textField.placeholder = @"输入1";

    }];

    [alert addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {

        textField.placeholder = @"输入2";

    }];

    [alert addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {

        textField.placeholder = @"输入3";

    }];

    

    [self presentViewController:alert animated:YES completion:nil];

}