I have a UITableViewController and a Prototype cell with a UITextField. When I change a textField.text in one of the cells I want it to be changed in all other cells which my tableView now have (for example multiply number by 2 and set to other cell's textField.text output).
This is the behaviour I want to implement: CLICK
Should I trigger a certain textField delegate method or it should be made in another way?
My code for now:
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
cell.numberTextField.delegate = self
}
//Delegate methods
func textFieldDidBeginEditing(_ textField: UITextField) {
textField.text = ""
textField.textColor = UIColor.systemBlue
}
func textFieldDidEndEditing(_ textField: UITextField, reason: UITextField.DidEndEditingReason) {
textField.text = "0"
textField.textColor = UIColor.black
}
At a high level:
UITextFieldDelegateThe most interesting work is in
textFieldDidChangeSelectionandcellForRowAt indexPathHere is an example of how I would do something like this:
1. Set up some custom types
2. Example of UITableView Cell, you can ignore if you have your own
3. Set up in view controller - you can skip if already set up, just here for completeness
4. TableView DataSource
5. TextField Delegate
6. TableView Delegate
End result is something like this:
Hope this gives you enough to set you on your way.