我在HomeScreen中使用Flatlist
,它显示了多个帖子。现在我想要的是,每当我从应用程序中退出或关闭应用程序,然后再打开应用程序时,我都应该能够看到Flatlist
中的第一项。
我尝试在我的渲染函数中使用scrollToIndex
,但它给了我一个错误 -undefined is not an object (evaluating '_this2.refs.flatListRef.scrollToIndex')
<FlatList
data={this.state.data}
ref={(ref) => { this.flatListRef = ref; }}
renderItem={ ({item,index}) => this._renderItem(item,index) }
extraData={[ this.state.data, this.state.checked ]}
/>
我曾尝试在componentDidMount
和render
函数中使用以下代码this.refs.flatListRef.scrollToIndex({animated: true,index:0});
,但是没有成功。
this.flatListRef.scrollToIndex({animated: true,index:0})
来解决。 - Pritish Vaidya