【发布时间】:2019-02-15 04:05:50
【问题描述】:
当我的 tableView 进入编辑模式时,单元格的每一侧都有一个图标:右侧的图标是重新排列单元格顺序的默认图标,左侧的图标是删除单元格的默认图标.我可以轻松地与重新排列图标进行交互,没有任何问题,但是,点击删除图标没有响应。它仅在我笨拙地向右滑动然后向左滑动时才有效。下面我将我认为与我的情况相关的所有代码都放在了下面。
一些背景信息:我在视图中有三个触摸手势(单击、双击和长按)。我尝试使用启用编辑模式的条件禁用它们。我什至尝试过事先删除触摸手势,但这并没有帮助。我认为这可能是一个自动布局问题,没有为删除按钮注册区域,但是重新排列按钮可以工作,所以这不应该吗?我的单元格的前导和尾随常数都是 +10 的视图。此外,isEditing 由 UIButton 控制。最后,我将 tableView 委托设置为 self,并在启用编辑时进行触摸交互。
任何帮助将不胜感激。谢谢!
override func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
if isEditing { return true }
return false
}
override func tableView(_ tableView: UITableView, editingStyleForRowAt indexPath: IndexPath) -> UITableViewCell.EditingStyle {
if isEditing { return .delete }
return .none
}
override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) {
if (editingStyle == .delete) {
countBeforeDeletingCell = dataSource.data.count
dataSource.data.remove(at: indexPath.row)
tableView.deleteRows(at: [indexPath], with: .none)
}
}
override func tableView(_ tableView: UITableView, moveRowAt sourceIndexPath: IndexPath, to destinationIndexPath: IndexPath) {
let movedObject = dataSource.data[sourceIndexPath.row]
dataSource.data.remove(at: sourceIndexPath.row)
dataSource.data.insert(movedObject, at: destinationIndexPath.row)
tableView.reloadData()
}
【问题讨论】:
标签: ios swift uitableview