0

I made a table view that fills the cells with some data, which works fine.

The problem is that, when I scroll the table, all the cells get mixed, do you know a way to stop this?

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let celda = tabla_reportes.dequeueReusableCellWithIdentifier("celda", forIndexPath: indexPath) as! celdaReportes
    switch indexPath.section {
    case 0:
        celda.datos = tipos
        celda.back = UIColor.lightGrayColor()
    case 1:
        celda.index = indexPath.row
        celda.datos = fillArrayWithData(datos[indexPath.row] as! NSDictionary)
        celda.back = UIColor.clearColor()
    default:
        break
    }
    celda.delegate = self
    return celda
}
xgord
  • 4,606
  • 6
  • 30
  • 51
Luis Perez
  • 111
  • 8

2 Answers2

0

Because the cells are reused for performance. Eg, when you scroll up the tableview and the number 1 cell disappears, the number 10 cell is actually your number 1 cell. Whatever you set in number 1 cell and the value is not updated stays with number 10 cell and so on...Try put a blank value inside your cell if it has no value.

Peter Lee
  • 106
  • 7
0

you should update field of the cell. maybe you here UITableViewCell reuse good practice can help you

Community
  • 1
  • 1
hecvstyle
  • 71
  • 5