Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/118.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 带有自定义UITextField的UIAlertController_Ios_Swift_Uialertcontroller - Fatal编程技术网

Ios 带有自定义UITextField的UIAlertController

Ios 带有自定义UITextField的UIAlertController,ios,swift,uialertcontroller,Ios,Swift,Uialertcontroller,我试图使用一个自定义的UITextField,更准确地说是AKMaskField() 但我运气不好,这是我的代码,一个简单的UIAlertController: @IBAction func buttonClick(sender: AnyObject) { var alert = UIAlertController(title: "Vincular CPF", message: "Digite seu CPF para acumular mais pontos no seu prog

我试图使用一个自定义的UITextField,更准确地说是AKMaskField()

但我运气不好,这是我的代码,一个简单的UIAlertController:

 @IBAction func buttonClick(sender: AnyObject) {

    var alert = UIAlertController(title: "Vincular CPF", message: "Digite seu CPF para acumular mais pontos no seu programa de fidelidade (Somente números)", preferredStyle: UIAlertControllerStyle.Alert)

    alert.addTextFieldWithConfigurationHandler(textFieldConfig) //Line with error
    alert.addAction(UIAlertAction(title: "Cancelar", style: UIAlertActionStyle.Cancel, handler: handleCancelButton))
    alert.addAction(UIAlertAction(title: "Enviar", style: UIAlertActionStyle.Default, handler: {
            (UIAlertAction) in
            println("ok")
        }))



    self.presentViewController(alert, animated: true, completion: {


    })

}

func textFieldConfig(textField: AKMaskField){
    textField.mask = "{ddd}.{ddd}.{ddd}-{dd}"
    textField.maskTemplate = "x"
    textField.maskShowTemplate = true

    //textField.keyboardType = .NumberPad
    //textField.placeholder = "00000000000"
}
以下是错误消息:

 Cannot invoke 'addTextFieldWithConfigurationHandler' with an argument list of type '((AKMaskField) -> ())'
错误很明显,我尽了一切努力强制对UITextField进行向下转换,但似乎没有任何效果


有人知道我该如何实现这一点吗?

尝试制作另一个函数:

let config = {(textField: UITextField) in textFieldConfig((textField as? AKMaskField)!)}
alert.addTextFieldWithConfigurationHandler(config) //Line with error

尝试创建另一个函数:

let config = {(textField: UITextField) in textFieldConfig((textField as? AKMaskField)!)}
alert.addTextFieldWithConfigurationHandler(config) //Line with error

这将不会编译,因为
UIAlertController
正在实例化
UITextField
。我找不到允许您使用自定义类(如
AKMaskField
)替换is的公共接口-但是您可以在配置处理程序中设置委托并从那里进行自定义。

这不会编译,因为
UIAlertController
正在实例化
UITextField
。我找不到允许您使用自定义类(如
AKMaskField
)替换is的公共接口-但是您可以在配置处理程序中设置委托并从那里进行自定义。

我必须更改为
(textField:UITextField!)
编译,当我单击该按钮时,我收到以下错误消息:无法将类型为“\u UIAlertControllerTextField”(0x109a40b88)的值强制转换为“Test\u iOS\u Application.AKMaskField”(0x106ce6e60)。因此
AKMaskField
不扩展
UIAlertControllerTextField
?你能修改它吗?我试图扩展它,但我得到一个错误:使用未声明的类型“UIAlertControllerTextField”我忘记了
UIAlertControllerTextField
是私有的。您必须手动进行自定义(即,在配置处理程序中,通过从
AKMaskField
复制/粘贴代码)。我必须更改为
(textField:UITextField!)
进行编译,当我单击按钮时,我收到以下错误消息:无法强制转换类型为“\u UIAlertControllerTextField”(0x109a40b88)的值至“测试iOS应用程序.AKMaskField”(0x106ce6e60)。因此,
AKMaskField
没有扩展
UIAlertControllerTextField
?您可以修改它吗?我试图扩展它,但出现了一个错误:使用未声明的类型“UIAlertControllerTextField”我忘记了
UIAlertControllerTextField
是私有的。您必须手动进行自定义(即,在配置处理程序中,通过从
AKMaskField
复制/粘贴代码。我该怎么做?我对swift有点陌生,该怎么做?我对swift有点陌生