Ios 带有自定义UITextField的UIAlertController
我试图使用一个自定义的UITextField,更准确地说是AKMaskField() 但我运气不好,这是我的代码,一个简单的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
@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有点陌生