如何使用Swip手势在每个表视图单元格上执行“编辑”和“删除”操作?像电子邮件应用程序的东西!有什么建议吗?
答案 0 :(得分:0)
func tableView(_ tableView: UITableView, canEditRowAt indexPath:
IndexPath) -> Bool {
// Return NO if you do not want the specified item to be editable.
return true
}
// Override to support editing the table view.
func tableView(_ tableView: UITableView, commitEditingStyle
editingStyle: UITableViewCellEditingStyle, forRowAt indexPath:
IndexPath) {
if editingStyle == .delete {
// Delete the row from the data source
tableView.deleteRows(at: [indexPath], with: .fade)
}
else if editingStyle == .insert {
// Create a new instance of the appropriate class, insert it
into the array, and add a new row to the table view
}
}