我有一个带有多个自定义单元格的UITableView。所有类型单元格的高度都是由UITableViewAutomaticDimension计算的。
当正常滚动时,它工作正常。但是当滚动速度非常快时,它会返回奇怪的高度。在我滚动并返回到它之后,它再次正确地重新加载。
我尝试检查uitableview是否快速滚动并重新加载表格,如下所示:
func scrollViewDidScroll(scrollView: UIScrollView) {
if scrollView.panGestureRecognizer.velocityInView(self.view).y < -750
fastScroll = true
}
}
func scrollViewDidEndDragging(scrollView: UIScrollView, willDecelerate decelerate: Bool) {
if fastScroll {
fastScroll = false
myTableView.reloadData()
}
}虽然这个方法运行良好,但我对这个解决方案并不满意。有人能给我指出正确的解决方案吗?
发布于 2016-08-29 15:27:15
因此,只有当我插入或删除单元格时,才会发生这种异常。我可以通过添加setNeedsLayout()和layoutIfNeeded()来解决这个问题
myTableView.beginUpdates()
myTableView.deleteSections(deleteIndexes, withRowAnimation: .None)
myTableView.insertSections(insertIndexes, withRowAnimation: .None)
myTableView.reloadSections(reloadIndexes, withRowAnimation: .None)
myTableView.endUpdates()
myTableView.setNeedsLayout()
myTableView.layoutIfNeeded()https://stackoverflow.com/questions/39164722
复制相似问题