I created multiple text fields programatically. Their input is being read and after the answer is checked a new question is being posed to the user.
But I don't seem to be able to clear the text fields, the previous input is still there.
I tried already to add textfield.text = ""
but it doesn't seem to work. Maybe I should somehow delete the textfield with the correct tag, but I don't know how to do that. Does anybody have a suggestion for this situation?
var a = 0
while a < aantalNoten {
let myTekstveld = UITextField()
if (view.viewWithTag(a+1) as? UITextField) != nil {
myTekstveld.text = ""
}
else {
myTekstveld.frame = CGRect(x: labelX, y: labelY + 100, width: labelWidth, height: labelHeight / 2)
myTekstveld.backgroundColor = UIColor.white
myTekstveld.textAlignment = .center
myTekstveld.placeholder = "?"
myTekstveld.keyboardType = UIKeyboardType.default
myTekstveld.borderStyle = UITextField.BorderStyle.line
myTekstveld.autocorrectionType = .no
myTekstveld.returnKeyType = UIReturnKeyType.done
myTekstveld.clearButtonMode = UITextField.ViewMode.whileEditing
myTekstveld.textColor = UIColor.init(displayP3Red: CGFloat(96.0/255.0), green: CGFloat(35.0/255.0), blue: CGFloat(123.0/255.0), alpha: 1)
myTekstveld.delegate = self as? UITextFieldDelegate
myTekstveld.tag = a + 1
view.addSubview(myTekstveld)
}
a += 1
labelX += labelWidth
}