Reputation: 1
I am new to swift 4 and iOS dev. I basically have 2 textfield's and 9 buttons, each button is labelled through 1 - 9. When I press a button, that button's value should appear on the first textfield and whenever the value of the 1st textfield is changed, it should multiply the current value in the textfield1 by 2 and display it on textfield2.
So far, I have managed to populate the 1st textfield whenever the numbered buttons are pressed but the difficulty is arising when multiplying the number from the current value of textfield1 and populating it to textfield2.
I have tried using the 'EditingChange' action on the textfield1 but that only gets called when I use the physical mac keyboard and not the buttons that I have created.. anyone have any ideas?
The following action gets called when I update the contents on textfield1 using the physical keyboard and not the buttons I have created: (EditingChange action)
@IBAction func textfield1(_ sender: Any) {
print("..rgjnrfgjn");
}
Upvotes: 0
Views: 75
Reputation: 5360
If you are familiar with delegates then you can use delegate method of TextField and it is called whenever anything new is written in text feild.
extension MyViewController: UITextFieldDelegate {
func textField(_ textField: UITextField,
shouldChangeCharactersIn range: NSRange,
replacementString string: String) -> Bool {
let text = textField.text,
return true
}
}
Upvotes: 1