I just created a tableView and I want to implement a function which allows the user to delete a row. For this I have implemented this function:
func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) {
if editingStyle == .delete {
// Zeile löschen (Z.b. dann aus dem Array oder aus dem dauerhaftem CoreData)
tableView.deleteRows(at: [indexPath], with: .fade)
}
}
But you still have to know for my question that I configured my cell with this code:
let cell = tableView.dequeueReusableCell(withIdentifier: "timerCell", for: indexPath) as! timerTableViewCell
cell.layer.borderWidth = 1
// cell.layer.borderColor = CGColor(red: 41 / 255, green: 171 / 255, blue: 226 / 255, alpha: 1)
cell.layer.borderColor = CGColor(red: 0, green: 0, blue: 0, alpha: 1)
cell.textLabel?.text = "Timer"
cell.detailTextLabel!.text = "12:40"
cell.layer.cornerRadius = 18
cell.clipsToBounds = true
cell.layoutMargins.left = 30
cell.layoutMargins.right = 30
return cell
But now I have a problem with deleting the cells and the frame of my cell: My cell has a round border and if I now want to delete this cell in my app, the border suddenly becomes square and does not become again round even after the deletion is canceled. Unfortunately that looks very bad. Here are the screenshots:
Has anyone ever had this problem or ideas and could help me?
2
Answers
That would imply that the cell’s
CALayer
is being reconstructed (probably when the cell is resized to show the delete button).You might want to create a custom view cell class and override the
func layoutSublayers(of: CALayer)
of the cell (which it inherits though UIView and CALayerDelegate). Inside of that method you can call super then set the corner radius on your view’s layer.I have now tried something new and simply put a view on my cell and then round out this view instead of the cell directly. But I always get an error message with the required init. This is my code: