2017-04-26 1 views
0

J'ai une tableView dans mon Viewcontroller, je veux changer la couleur d'arrière-plan de la cellule uniquement lorsque l'utilisateur clique sur le bouton Modifier dans la cellule.Changer la couleur de la cellule en cliquant sur le bouton d'édition

Ce que je l'ai fait jusqu'à présent est

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 
    let cell = tableView.dequeueReusableCell(withIdentifier: "taskcell", for: indexPath as IndexPath) as! taskListCell 
    cell.backgroundColor = colorMediumGreen 
    // Configure the cell… 
    let tableData = self.tableData[indexPath.row] 
    cell.duration.text = tableData[""] as? String 
    cell.taskDetail.text = tableData[""] as? String 

    return cell 

} 
func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? { 

    let editAction = UITableViewRowAction(style: .normal, title: "Erledigt") { (rowAction, indexPath) in 

    } 

    editAction.backgroundColor = .red 

    return [editAction] 
} 
+0

Procurez-vous la cellule avec l'aide de 'IndexPath' et mettre à jour cette cellule dans' 'editAction . –

+0

@DharmeshKheni: pouvez-vous s'il vous plaît expliquer comment? – SwiftUser

Répondre

1

J'ai résolu ce problème :-)

func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? { 


    let editAction = UITableViewRowAction(style: .normal, title: "Edit") { (rowAction, indexPath) in 

     let cell = self.tableView(tableView, cellForRowAt: indexPath) 
     cell.contentView.backgroundColor = colorLightGray 

     self.tableView.reloadData() 
     self.tableView.endUpdates() 
    } 

    editAction.backgroundColor = .red 

    return [editAction] 
} 
+0

C'est génial .. :) –