【发布时间】:2018-03-15 07:43:42
【问题描述】:
我已经在 UITableView 上实现了滑动删除,它可以在默认行为下正常工作,即单元格的内容在像在图像上一样滑动时向左移动。我想要实现(自定义)的是在滑动时让这个删除按钮出现在单元格内容上,即单元格中的文本不会移动。
我正在使用这种方法
func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? {
let delete = UITableViewRowAction(style: .destructive, title: "Delete") { (action, indexPath) in
self.deletionDidStart(of: self.element(for: indexPath)!, at: indexPath)
// use helper function to delete element at given index path
let deleted = self.deleteElement(for: indexPath)
// refresh tableView
self.tableView.beginUpdates()
self.tableView.deleteRows(at: [indexPath], with: .automatic)
if let deletedSection = deleted.section {
self.tableView.deleteSections(IndexSet(integer: indexPath.section), with: .automatic)
self.deletedSection(deletedSection, at: indexPath)
}
self.tableView.endUpdates()
// call deletion event handler
self.deletedElement(deleted.element!, at: indexPath)
}
return [delete]
}
【问题讨论】:
标签: ios swift uitableview