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

标签 ios swift uitableview

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

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/

相关文章:

ios - 在 64 位 iOS7.1 模拟器上运行时自动布局代码崩溃

swift - 相同颜色的 TableView 和 TableView 单元格 swift

ios - 在 iOS 上的一个 UITableView 中加载两个不同的 Nib

没有分隔线的 iPhone 分组 View 边框

ios - CocoaPods AmazonMobileHub 架构 x86_64 的 undefined symbol

ios - 在 iOS 10 中动态调整 AVPlayer 的大小

Swift正确破解多层开关

swift - 是否可以录制来自 iPhone 的音频?

ios - 在 UISearchController Swift 中将标题与图像名称匹配

ios - 从 Parse 检索多个图像的更好方法