更改单元格删除按钮的文本

Wil*_*lls 2 uitableview ios swift

我正在尝试更改单元格的删除按钮。我有两个功能:

override func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? {
    let titleBtn = UITableViewRowAction(style: UITableViewRowActionStyle.default, title: "Supprimer") { (action , indexPath ) -> Void in
        self.isEditing = false
    //ackAction.backgroundColor = UIColor.orange
    }
    return [titleBtn]
}


override func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
    return true
}
Run Code Online (Sandbox Code Playgroud)

但是,当我运行我的应用程序时,按钮的文本已更改,但删除不起作用(我无法从数组和 tableview 的行中删除数据)。在添加此功能之前,一切都完美无缺。一个细节:在canEditRowAt函数中,我也试图返回 false ......提前致谢

Aym*_*him 5

如果要更改删除按钮的文本,请在以下内容中使用此方法UITableViewDelegate

func tableView(_ tableView: UITableView, titleForDeleteConfirmationButtonForRowAt indexPath: IndexPath) -> String?
{
     return "Your new title"
}
Run Code Online (Sandbox Code Playgroud)

要从数组中删除项目,请遵循此方法

func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) 
{
    if (editingStyle == UITableViewCellEditingStyle.delete) 
    {
        yourDataSourceArray.remove(at: indexPath.row)
        yourTableView.reloadData()
    }
}
Run Code Online (Sandbox Code Playgroud)