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
})
您发布的代码不会尝试设置占位符。你是说'textField.text =“当前引脚名称”行没有真正设置文本字段的文本? – rmaddy
@rmaddy没错。 textField.text =“当前引脚名称”在提示textField时返回空白。我从我的代码中删除了占位符行,因为它工作正常。 –
你是什么意思“提示textField时返回空白”? – rmaddy