I send a parameter from my viewController to customCell. My custom cell has a textField. In my viewController I have a string variable for storing the value in textField, because this value I will send to a rest services.
MyCustomCell
customCell: TableViewCell: {
var data: String?
@IBOutlet weak var textField: UITextField!
override func awakeFromNib() {
super.awakeFromNib()
textField.delegate = self
}
func setData(data: inout String) {
self.data = data
}
}
extension customCell: UITextFieldDelegate {
func textFieldDidEndEditing(_ textField: UITextField) {
data = textField.text ?? ""
}
}
MyViewController
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "customCell", for: indexPath) as! customCell
cell.setData(data: &data.email)
return cell
}
When I sent the reference to the customCell, I lost the reference in the textFieldDidEndEditing method.