我发现了类似的问题。这些都不能解决我遇到的同样问题。 这个在这里:Table view cell background goes white when deleting a cell - iOS 在 objective-c 中。我需要一个快速的答复。
我找到了这个 Change default background color while deleting a row from tableView swift 回答但是当我将它添加到我的代码时它仍然不起作用。
这是我用来删除单元格的代码。
override func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? {
let delete = UITableViewRowAction(style: .destructive, title: "delete") { (action, indexPath) in
let alertController = UIAlertController(title: "Warning", message: "Are you sure you want to delete this?", preferredStyle: .alert)
let deleteAction = UIAlertAction(title: "Delete", style: .destructive, handler: { (action) in
self.tableView.deleteRows(at: [indexPath], with: .fade)
})
alertController.addAction(deleteAction)
let cancelAction = UIAlertAction(title: "Cancel", style: .default, handler: nil)
alertController.addAction(cancelAction)
self.present(alertController, animated: true, completion: nil)
}
return [delete]
}
我需要保持单元格的颜色,因为删除选项来自滑动。
谢谢!
最佳答案
删除单元格后重新加载表格,并从数组中删除单元格数据,或者在 View 中使用此行确实加载
tableView.tableFooterView = UIView(frame: .zero)
这将删除空单元格表格
关于ios - Swift 4,删除单元格时背景颜色变为白色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52283192/