【发布时间】:2017-04-03 00:19:08
【问题描述】:
如何使用 Swip 手势对每个表格视图单元格执行“编辑”和“删除”操作?类似于电子邮件应用程序!有什么建议吗?
【问题讨论】:
标签: swift3 tableviewcell swipe-gesture
如何使用 Swip 手势对每个表格视图单元格执行“编辑”和“删除”操作?类似于电子邮件应用程序!有什么建议吗?
【问题讨论】:
标签: swift3 tableviewcell swipe-gesture
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
}
}
【讨论】: