UITableViewController cells are blank / Somem when scrolling to TableView

0

I'm having a problem with my tableviewcontroller, as I update some data in a textfield or roll down it goes away with some cells, if I scroll up and down hiding the cell that disappeared it appears again as if I have reloaded, I tried to reload every time I edit but it does not work? Has anyone ever had anything similar? I'm using a custom cell

My cellforRowAt is like this

fieldValues = metadataBuilder.fieldValues
return metadataBuilder.cells[indexPath.row]

metadatabuilder and an object with an array of uitableviewcell

    
asked by anonymous 06.07.2018 / 18:22

1 answer

0

The operation of a UITableView can be summarized as a list that loads only the required data (the ones being shown) while removing from the memory cells that have already been loaded and exiting the screen, as in your case where the value within UITextField of a cell gets lost when it exits screen display.

The operation described by you is only achieved if you save the value of the UITextField and again assign the value when the cell is initialized in cellForRow .

Something similar to this:

func cellForRow(at: IndexPath) -> UITableViewCell? {
     ...
     cell.textField.tag = indexPath.row
     cell.textField.delegate = self
     cell.textField.text = self.arrayDeValores[indexPath.row]
     ...
     return cell
}

For the part of saving the inserted texts in the array you will need to implement UITextFieldDelegate for each one then: / p>

func textFieldDidEndEditing(_ textField: UITextField){
     self.arrayDeValores[textField.tag] = textField.text ?? ""
}

Do not forget to declare the array as a class-wide variable. The tag property is used to identify the correct textfield.

    
10.07.2018 / 05:13