Uitableviewcontroller cells are blank/missing when scrolling the Tableview

Asked

Viewed 70 times

0

I’m having a problem with my tableviewcontroller, as I update some data on a textfield or roll down it goes disappearing with some cells, if I roll up and down hiding the missing cell it comes back to appear as if it had recharged, I tried to give Load every time I edit but it doesn’t work ? someone has had something 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 a uitableviewcell array

1 answer

0


The functioning of a Uitableview can be summarized as a list that only loads the required data (the ones being shown) while removing from memory cells that have already been loaded and disappear from the screen, as in your case where the value within the Uitextfield of a cell is lost when exiting the screen display.

The operation described by you is only achieved if you save the Uitextfield value and again assign the value when the cell is initialized in the 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
}

As for the saving part of the inserted texts in the array you will need to implement Uitextfielddelegate for each one for then:

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

Don’t forget to declare the array as a class scope variable. The property tag is used to identify the correct textfield.

  • Opa I could solve and I forgot to post here, but I believe that this solution and also work in my case I saved an array with the size of each cell to be able to set in heighForRowAt, apparently he put a smaller size for cell and it did not appear, But thanks for the young attention

Browser other questions tagged

You are not signed in. Login or sign up in order to post.