UITableView.ScrollRectToVisible()不会滚动到底部

rih*_*iha 1 scroll uitableview xamarin.ios

我有一个包含可变数量的部分和自定义单元格的表视图.在某些情况下,单元格可能会在RowSelected()内调整大小.每当发生这种情况时,我还要确保在调整大小(放大)后单元格完全可见.

我在另一个表中工作,只是修改基础数据,以便表视图源将提供更大的单元格.然后我重新加载单元格并将其滚动显示如下:

// Modify data
//...

// Reload cell
tableView.ReloadRows(new NSIndexPath[] { indexPath }, UITableViewRowAnimation.None);
tableView.ScrollRectToVisible(tableView.CellAt(indexPath).Frame, true);
Run Code Online (Sandbox Code Playgroud)

问题出现在表视图中,其中调整大小不仅可以由RowSelected()触发,还可以由单元格内的UI元素上的事件触发.

然后事件调用一个方法来重新加载单元格:

void updateCell() {
  if (cell.Superview != null) {
    UITableView tableView = (UITableView)cell.Superview;
    tableView.ReloadRows(new NSIndexPath[] { indexPath }, UITableViewRowAnimation.None);

    // Get the new (possibly enlarged) frame
    RectangleF frame = tableView.CellAt(indexPath).Frame;
    Console.WriteLine("This really is the new large frame, height: {0}", frame.Height);

    // Try to scroll it visible
    tableView.ScrollRectToVisible(frame, true);
  }
}
Run Code Online (Sandbox Code Playgroud)

这适用于所有细胞,但最底部.它只会使该单元格的旧框架可见.我仔细检查它确实为ScrollRectToVisible()提供了新的单元格框架.

因此,似乎ScrollRectToVisible()绑定到表的旧内容大小 - 即使在重新加载行之后也是如此.我尝试通过提供新的内容大小和计算出的高度差来解决这个问题.这确实有效,但对我来说真的很烦人.

有一些更干净的方式做事吗?

提前致谢

小智 7

而是使用这个:

tableView.ScrollRectToVisible(_: animated: )
Run Code Online (Sandbox Code Playgroud)

用它来滚动UITableView到底行:

tableView.scrollToRow(at: at: animated: )
Run Code Online (Sandbox Code Playgroud)