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

时间:2016-07-16 21:12:18

标签: ios objective-c iphone uitableview

我有一个UITableview,有40到50个部分。它是可扩展的tableview,当曾经点击节标题扩展相应的部分,如果已经扩展它将关闭。我的问题是,当我点击部分标题请求服务器获取数据并从服务器接收数据时,我的Tableview会自动滚动到顶部,这仅在第20节之后发生。我无法理解什么是错的。

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

1 个答案:

答案 0 :(得分:1)

如果您执行某些更改某些单元格高度的操作,则表格将在重新加载后滚动到其他位置。 如果您希望在加载完成后将tableview滚动到tapped部分的顶部,那么类似于:

 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];
相关问题