I am trying to get the specific row (in a TableViewController) in which the textField that was just edited is located (I have a TableViewController with a custom tableViewCell that has two text fields in it), so I could save the textField input to that corresponding index in my array, and then to Realm.
I tried using a textField.tag as shown below in my code, however this had led to errors.
Thank you so much, any help would be much appreciated!:)
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> NotecardTableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "NotecardCell", for: indexPath) as! NotecardTableViewCell
cell.termTextField.delegate = self
cell.defTextField.delegate = self
cell.termTextField.accessibilityIdentifier = "termTextField"
cell.defTextField.accessibilityIdentifier = "defTextField"
cell.termTextField.tag = indexPath.row
cell.termTextField.text = noteCards?[indexPath.row].term
return cell
}
func textFieldDidEndEditing(_ textField: UITextField) {
do {
try! realm.write {
if textField.accessibilityIdentifier == "termTextField"{
noteCards?[textField.tag].term = textField.text ?? "default"
}
}
}
}