问题描述
我有一个带有自定义页脚视图的表格视图。当我尝试删除单元格时,它会跳转并在页脚之间留出空白。这是我使用的代码。
func tableView(_ tableView: UITableView,commit editingStyle: UITableViewCell.EditingStyle,forRowAt indexPath: IndexPath){
switch editingStyle {
case .delete :
self.items.remove(at: indexPath.row)
CATransaction.begin()
CATransaction.setCompletionBlock({
tableView.beginUpdates()
tableView.deleteRows(at: [indexPath],with: .none)
tableView.endUpdates()
})
tableView.setEditing(false,animated: true)
CATransaction.commit()
footerView.label.text = "text"
default :
return
}
}
解决方法
我认为您应该从数据源中删除指定的项目,并且不要干扰默认动画,如下所示:
func tableView(_ tableView: UITableView,commit editingStyle: UITableViewCell.EditingStyle,forRowAt indexPath: IndexPath){
switch editingStyle {
case .delete :
self.items.remove(at: indexPath.row)
// unless intended,you can avoid this letting the user to delete more items one afte the other
tableView.setEditing(false,animated: true)
footerView.label.text = "text"
default :
return
}
}