如果UIAlertView
为空白,我试图显示UITextfield
。我已使用以下example作为指导。我遇到的问题是,UIAlertView
为空白时,Textfield
不会出现。以下是称为
func displayMyAlertMessage(userMessage: String) {
let myAlert = UIAlertController(title: "Alert", message: userMessage, preferredStyle: UIAlertController.Style.alert)
let okAction = UIAlertAction(title: "Ok", style: UIAlertAction.Style.default, handler: nil)
myAlert.addAction(okAction)
self.present(myAlert, animated: true, completion: nil)
}
要将文本输入到UITextFiled
中,我使用了UIPickerview
控制器。
因此,我已将此功能合并到func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int)
中。这是该功能的代码。
func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
if TrackTextField.isFirstResponder {
selectedTrack = tracks[row]
guard let track = selectedTrack?.isEmpty else {
displayMyAlertMessage(userMessage: "You have to fill in a track")
return
}
TrackTextField.text = String(track)
} else if firstTextField.isFirstResponder {
firstDriver = drivers[row]
firstTextField.text = firstDriver
} else if secondTextField.isFirstResponder {
secondDriver = drivers[row]
secondTextField.text = secondDriver
} else if thirdTextField.isFirstResponder {
thirdDriver = drivers[row]
thirdTextField.text = thirdDriver
}
}
我已使用轨道的选择来测试displayMyAlertMessage函数是否起作用。任何帮助将不胜感激。