我在我的应用程序中使用了手风琴视图,当我在UITableView
中插入新行时,如果该部分位于可见区域,则一切正常。但是当我们更新下部分行时,UITableView
会自动滚动到顶部。这是什么问题?任何人都可以帮我解决这个问题吗?
[CATransaction begin];
[CATransaction setCompletionBlock:^{
NSLog(@"Completed");
}
[self.tableView beginUpdates];
[self.tableView insertRowsAtIndexPaths: indexPathsToInsert withRowAnimation: UITableViewRowAnimationAutomatic];
[self.tableView deleteRowsAtIndexPaths:indexPathsToDelete withRowAnimation:UITableViewRowAnimationAutomatic];
[self.tableView endUpdates];
[CATransaction commit];
有什么建议吗?我尝试了scrollToRowAtIndexPath
,setContentOffSet
。
答案 0 :(得分:3)
您是否使用autolayout让tableview计算单元格高度?如果是,则必须尽快将estimatedHeight
设置为单元格的实际高度。如果不同的细胞有不同的高度:
func tableView(_ tableView: UITableView, estimatedHeightForRowAt
indexPath: IndexPath) -> CGFloat
“accordian tutorial”有效,因为它使用固定的单元格高度。
答案 1 :(得分:0)
我没有尝试,但这里列出了你可以尝试的事项:
self.tableView.scrollEnabled = NO
,在self.tableView.scrollEnabled = YES
self.tableView.scrollsToTop = NO
CGPoint
中保存scrollView的当前位置,然后在更新通话后[self.tableView setContentOffset:previousPosition animated:NO]
希望这有帮助。