我正在尝试更改单元格的删除按钮。 我有两个功能:
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
}
但是,当我运行我的应用程序时,按钮的文本已更改,但删除不起作用(我无法从数组和表格 View 的行中删除数据)。在添加此功能之前一切正常。
一个细节:在 canEditRowAt
函数中,我也尝试返回 false ...
提前致谢
最佳答案
如果要更改删除按钮的文本,请在 UITableViewDelegate
中使用此方法:
func tableView(_ tableView: UITableView, titleForDeleteConfirmationButtonForRowAt indexPath: IndexPath) -> String?
{
return "Your new title"
}
删除数组中的项符合此方法
func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath)
{
if (editingStyle == UITableViewCellEditingStyle.delete)
{
yourDataSourceArray.remove(at: indexPath.row)
yourTableView.reloadData()
}
}
关于ios - 更改单元格删除按钮的文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46873124/