ios - 为什么 UITableview 在重新加载数据时向上滚动

标签 ios objective-c iphone uitableview

我有一个包含 40 到 50 个部分的 UITableview。它是可扩展的表格 View ,当点击部分标题时正在扩展相应的部分,如果已经展开它将关闭。我的问题是,每当我点击部分标题请求服务器数据并从服务器接收数据时,我的 Tableview 会自动滚动到顶部,这仅发生在第 20 部分之后。我不明白出了什么问题。

NSIndexSet *sections = [NSIndexSet indexSetWithIndex:self.selectedIndexPath.section];
[self.tableview reloadSections:sections withRowAnimation:UITableViewRowAnimationFade];

最佳答案

如果您更改了某些单元格的高度,表格将在重新加载后滚动到不同的位置。 如果您希望 tableview 在加载完成后滚动到点击部分的顶部,可以这样:

 NSIndexSet *sections = [NSIndexSet indexSetWithIndex:section];
 [self.tableView reloadSections:sections withRowAnimation:UITableViewRowAnimationFade];

 NSIndexPath     *sectionPath = [NSIndexPath indexPathForRow:NSNotFound inSection:section];
 [self.tableView scrollToRowAtIndexPath:sectionPath atScrollPosition:UITableViewScrollPositionTop animated:YES];

关于ios - 为什么 UITableview 在重新加载数据时向上滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38415675/

相关文章:

ios - 是否可以在不显示 UIActivityViewController 对话框且不需要 Facebook SDK 的情况下通过 FB Messenger 从 iOS 应用程序共享 url 链接?

ios - 自定义过渡动画显示 viewController 并闪烁

javascript - iOS 中的 Exif 方向问题

ios - NSCondition 或 @synchronized

ios - HealthKit Watch 应用程序未记录卡路里

ios - 无法导入 UIKit

iphone - NSData dataWithContentsOfURL : stopped working in iOS 6

iPhone iOS 如何以编程方式创建色调和阴影?

程序终止后 Objective-c 和内存泄漏?

iphone - nsurlconnection异步请求