ios - Swift 4,删除单元格时背景颜色变为白色

标签 ios swift uikit

我发现了类似的问题。这些都不能解决我遇到的同样问题。 这个在这里: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/

相关文章:

ios - 在 UITextView 的属性文本中的最后一个字符之后调用链接方法

ios - 在可重用的 UIView 中,我应该将 UIButtons 的选择器放在哪里?

swift - 如何在 Swift2 中使用泛型类型

ios - 在 Swift 中重新加载 UIScrollView 中的 UITableView

ios - 委托(delegate)协议(protocol)的实现方法在哪里调用?

iphone - iOS 中的委托(delegate)

IOS UIActivityViewController

ios - 注销时如何从 uber API 中删除访问 token ?

swift - 如何在 UITableView 中设置 Section 属性?

ios - 应用程序在 gpus_ReturnNotPermittedKillClient 崩溃