U
U
uzolenta2019-11-08 11:18:43
Swift
uzolenta, 2019-11-08 11:18:43

How to get data from table cells?

How to get textField data from table cells? To save the data to an array when the button is clicked.
5dc5239f8cb74859223064.png
What needs to be implemented:
1. When you click on the Add button, a new form is added to fill in
2. When you click on the Save button, the data from the cells is saved to an array
. I implement it through tableView, maybe you can suggest another scheme for implementation.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
doublench21, 2019-11-08
@doublench21

Well, get a dictionary var data = [IndexPath: String]()and UITextFieldDelegate. And in the delegate method, do this:

func textFieldDidEndEditing(_ textField: UITextField){
    let pointInTable = textField.convert(textField.bounds.origin, to: tableView)
    guard let textFieldIndexPath = tableView.indexPathForRow(at: pointInTable) else { return }
    guard let text = textField.text else { return }
    data[textFieldIndexPath] = data[textFieldIndexPath, default: ""] + text
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question