I have a UITextField
that will be used to input the data of time (10,15,30 minutes etc). I want right after the user manually input the minute data, then I will check, if it is more than zero or not ( negative or zero is not allowed), if the value is below 1 then I will show the alert.
I have tried to use the code below, but it doesn't work :
func textFieldShouldEndEditing(_ textField: UITextField) -> Bool {
if textField == numberReminderTextField {
let valueNumber = Int(numberReminderTextField.text ?? "0") ?? 0
if valueNumber < 1 {
showAlert(alertTitle: "Sorry", alertMessage: "The number you input is invalid, please input the number that more than zero.", actionTitle: "Back")
}
}
return false
}
In my opinion, you shouldn't do this checking in textFieldShouldEndEditing
. You can do the checking in textFieldDidEndEditing
or set your custom observer on .editingChanged
control event.
I.E.
textField.addTarget(self, action: #selector(yourCheckAction), for: .editingChanged)
If the alert still not show up, you should look into your showAlert
function.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments