how do uitextfield appear message must be filled first before it can be executed? I've searched Google but can't find it.
Asked
Active
Viewed 46 times
1 Answers
0
Do you mean display a message saying that the textFields must be filled before advancing? If so, use an if statement on each textField
if namaField.text == "" || alamatField.text == "" || phoneField.text == "" {
let alertController = UIALertController(title: "Enter all fields", preferredStyle: .alert)
let okayAction = UIAlertAction(title: "Okay", style: .default, handler: { action in
self.dismiss(animated: true, completion: nil)
})
alert.addAction(okayAction)
self.present(alert, animated: true)
}

LHowlett97
- 41
- 3
-
great, I will try – dante Aug 24 '20 at 01:21
-
you should check textField empty with isEmpty variable: namaField.text.isEmpty – goat_herd Aug 24 '20 at 01:25
-
2@goat_herd better to simply use `UIKeyInput` property `hasText` https://developer.apple.com/documentation/uikit/uikeyinput/1614457-hastext `if !(namaField.hasText && alamatField.hasText && phoneField.hasText) {` – Leo Dabus Aug 24 '20 at 01:32