2016-11-13 91 views
1

下面是我尝试的代码。 textField.placeholder完美工作,我需要为在UIAlertController中使用addTextField创建的textfield设置默认文本。如何在Swift中为UIAlertController中的addTextField设置默认文本

 let getPinNameAlert = UIAlertController(title: title, message: message, preferredStyle: .alert) 
     getPinNameAlert.addTextField(configurationHandler: { (textField) -> Void in 
     // textField.placeholder = "Pin Name" 
     textField.text = "Current Pin Name" 
     textField.keyboardType = UIKeyboardType.default 
     textField.clearsOnBeginEditing = true 
    }) 
+0

您发布的代码不会尝试设置占位符。你是说'textField.text =“当前引脚名称”行没有真正设置文本字段的文本? – rmaddy

+0

@rmaddy没错。 textField.text =“当前引脚名称”在提示textField时返回空白。我从我的代码中删除了占位符行,因为它工作正常。 –

+0

你是什么意思“提示textField时返回空白”? – rmaddy

回答

1

删除线textField.clearsOnBeginEditing = true

默认情况下,警报会自动对文本字段,这就是为什么你设置文本正在被清除。

相关问题