swiftuitableviewreuseidentifier

tableview cells mix after scrolling (swift)


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
}

Solution

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