I have a UITableView
with dynamic cells (in previous View are sliders to create these cells).
Each row contains two TextFields.
First is distance from start.
Second is description.
I can access these textFields through a cell in tableView. My tableView:
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cellIdentifier = "Cell"
let cell: FirstAddPointTableViewCell = self.tableView.dequeueReusableCell(withIdentifier: cellIdentifier, for: indexPath) as! FirstAddPointTableViewCell
cell.numberOfCell.text? = "\(indexPath.row + 1)."
cell.distance.text? = arrayTextField1[indexPath.row]
cell.description.text? = arrayTextField2[indexPath.row]
cell.distance.tag = indexPath.row
cell.description.tag = indexPath.row
cell.distance.delegate = self
cell.description.delegate = self
return cell
I have in my code func textFieldDidEndEditing
but I don't know how to access the textFields - distance and description to save the right values to my two arrays.
I know that this code is ok for only one textField. If I have two textFields this code is wrong:
func textFieldDidEndEditing(_ textField: UITextField) {
print("End editing!")
if textField.text != "" {
arrayTextField1[textField.tag] = textField.text!
arrayTextField2[textField.tag] = textField.text!
} else if textField.text == "" {
arrayTextField1[textField.tag] = textField.text!
arrayTextField2[textField.tag] = textField.text!
}
}
There is my FirstAddPointTableViewCell:
import UIKit
class FirstAddPointTableViewCell: UITableViewCell {
@IBOutlet weak var cislovaniPrekazek: UILabel!
@IBOutlet weak var prekazkyFormulare: UITextField!
@IBOutlet weak var poznamkyFormulare: UITextField!
override func awakeFromNib() {
super.awakeFromNib()
}
override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
}
}
My "idea" is something like this code (in textFieldDidEndEditing
) but I don't know how to do it. I can't gain access to them:
arrayTextField1[distance.tag] = distance.text!
arrayTextField2[description.tag] = description.text!
Can you help me please? Sorry for my English.