如何解决UITable视图滑动到已删除的跳转,并在单元格和自定义页脚视图之间留出空白
我有一个带有自定义页脚视图的表格视图。当我尝试删除单元格时,它会跳转并在页脚之间留出空白。这是我使用的代码。
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
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。