问题描述
在 NativeiOS 中,您可以使用以下方法使 UITableView 滚动到特定的 UITableViewCell:
In NativeiOS you can make a UITableView scroll to a particular UITableViewCell using:
[tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:87 inSection:0]
atScrollPosition:UITableViewScrollPositionMiddle animated:NO];
.. 或类似的.
例如,如果 ListView 包含 100 个项目,而我想滚动显示第 87 个项目.
For example, if the ListView held 100 items and I wanted to scroll such that the 87th item is visible.
查看 React Native ListView Docs 没有什么明显的.
Looking at the React Native ListView Docs there's nothing obvious there.
有没有人设法实现这一目标?我意识到 ListView 没有包装 UITableView 所以我们不能只公开这个方法.
Has anyone managed to achieve this? I realise that ListView does not wrap UITableView so we can't just expose the method.
似乎在 0.19-rc 版本中对此提供了一些支持,请查看 https://github.com/facebook/react-native/releases
Looks like some support for this is in the 0.19-rc release, check this https://github.com/facebook/react-native/releases
https://github.com/facebook/react-native/commit/33e05a1465f1f3e05a1465f1dc76c4130/a>
https://github.com/facebook/react-native/commit/33e05a11f00d1455f39b6dfef1c76c4130df02e5
推荐答案
使用 ScrollView
与 contentOffset={{ x: offsetX, y: offsetY }}
并根据要滚动到的行计算偏移变量.
Use a ScrollView
with contentOffset={{ x: offsetX, y: offsetY }}
and calculate the offset variables depending on which row you want to scroll to.
这篇关于React Native ListView:如何滚动到特定行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!