如何记住将来的单元格重复使用的indexpath?
我可以得到当前的收集视图。我使用的方法是:
var currentIndexPath: IndexPath = [0, 0]
func scrollViewDidScroll(_ scrollView: UIScrollView) {
let visibleRect = CGRect(origin: collectionView.contentOffset, size: collectionView.bounds.size)
let visiblePoint = CGPoint(x: visibleRect.midX, y: visibleRect.midY)
if let myIndexPath = collectionView.indexPathForItem(at: visiblePoint) {
currentIndexPath = myIndexPath
}
}
问题是:如何保存indexpath值,因此我将来可以称呼它 - 并用当前的indexpath值替换一些未来的Indexpath值?因此,它应该像书签一样工作 - 您可以回到那个地方,然后继续从那里来回滚动。
我试图将其保存到var(通过按钮点击)之类的:savedIndExpath = CurrentIndExpath
。但是,当我对其进行测试时 - 收集视图中的所有元素都看起来像是彼此的克隆。
I can get the current indexPath of a collectionViewCell. The method I use is this one:
var currentIndexPath: IndexPath = [0, 0]
func scrollViewDidScroll(_ scrollView: UIScrollView) {
let visibleRect = CGRect(origin: collectionView.contentOffset, size: collectionView.bounds.size)
let visiblePoint = CGPoint(x: visibleRect.midX, y: visibleRect.midY)
if let myIndexPath = collectionView.indexPathForItem(at: visiblePoint) {
currentIndexPath = myIndexPath
}
}
The question is: how can I save indexPath value, so in the future I can call it - and replace some future indexPath value with a current one? So it should work like a bookmark - you can go back to that place and continue scrolling back and forth from there.
I have tried just to save it to a var (e.x. via button tap) like this : savedIndexPath = currentIndexPath
. But when I gave it a test - all elements in the collectionView started to look like clones of each other.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论