【问题标题】:reloadRowsAtIndexPaths updates the contentOffset Of the table viewreloadRowsAtIndexPaths 更新 table view 的 contentOffset
【发布时间】:2015-03-11 21:21:49
【问题描述】:

我正在尝试从 tableview 重新加载特定行,但 tableview 的 contentOffset 在重新加载后重置为 (0, 0)。我尝试在 reloadRowsAtIndexPaths 周围添加 [tableview beginUpdates][tableview endUpdates] 但没有改变行为。

Calling reloadRowsAtIndexPaths removes tableView contentOffset这里提出了这个问题,但并没有解决问题。我很确定动画与这种行为无关。我不确定如何在重新加载 tableview 行的同时维护 tableview 的内容偏移量。

[tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];

【问题讨论】:

  • 这个功能你试过了吗:scrollToRowAtIndexPath:atScrollPosition:animated after reloading the row?
  • 是的,我试过scrollToRowAtIndexPath:atScrollPosition:animated,但没用。我尝试在重新加载行后设置 contentOffset,但 tableview 会跳转偏移量,这不是我想要的行为。我不希望在重新加载该 tableview 中的一行时更改 tableview 内容偏移量。
  • 有人对这个问题有意见吗?我仍在试图弄清楚如何解决这个问题,并且没有太多关于它的信息。
  • 看这个例子:photocity.googlecode.com/svn/trunk/PhotoCity_iPhone/co/… 这几乎就是你正在做的......它调用 [self setContentOffset:contentOffset animated:NO];
  • 此外,调用 deleteRowsAtIndexPaths 或 insertRowsAtIndexPath 时应调用 [tableview beginUpdates] 和 [tableview endUpdates],而不是使用 reloadRowsAtIndexPaths。希望对您有所帮助。

标签: ios objective-c uitableview reloaddata contentoffset


【解决方案1】:

我猜你已经实现了 tableView:estimatedHeightForRowAtIndexPath: 并让它返回 0。

reloadRowsAtIndexPaths:withRowAnimation: 之后,tableView 使用tableView:estimatedHeightForRowAtIndexPath: 中给出的估计高度来确定其偏移量。因此,除非您返回的值是准确的,否则执行它将导致您的 tableView 的偏移量在重新加载后发生变化。我遇到了类似的问题,并通过删除我的 tableView:estimatedHeightForRowAtIndexPath: 实现来修复它。

【讨论】:

    【解决方案2】:

    如果您尚未实现任何估计高度委托方法,使用更准确的值更新 estimatedRowHeightestimatedSectionHeaderHeight 也有助于缓解此问题。

    您可以使用视图检查器来查找单元格和标题的高度。

    【讨论】:

      猜你喜欢
      • 2011-09-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-17
      • 2019-07-26
      相关资源
      最近更新 更多