当UITextfield为空时,显示警报消息不出现

时间:2019-04-22 08:54:28

标签: ios uialertcontroller swift4.2 uipickerviewcontroller

如果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函数是否起作用。任何帮助将不胜感激。

0 个答案:

没有答案