我在我的应用程序中使用了 Accordion View ,当我在 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
。
最佳答案
您是否使用自动布局让表格 View 计算单元格高度?如果是,您必须尽快将 estimatedHeight
设置为 cell 的实际高度。如果不同单元格的高度不同:
func tableView(_ tableView: UITableView, estimatedHeightForRowAt
indexPath: IndexPath) -> CGFloat
“ Accordion 教程”之所以有效,是因为它使用了固定的单元格高度。
关于ios - 插入新行后如何停止 UITableView 滚动到顶部?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37944728/