当前位置: 代码迷 >> 综合 >> iOS tableview/collectionview索引联动之字母调动 (ndexPathsForVisibleItems返回不按顺序)
  详细解决方案

iOS tableview/collectionview索引联动之字母调动 (ndexPathsForVisibleItems返回不按顺序)

热度:36   发布时间:2024-03-09 09:00:00.0

不细说了,知道情景的看看:

在设置索引条与tableview(或collectionView)联动时,滑动tableview,索引条字母不按顺序变色,会隔几个。这是因为:

indexPathsForVisibleItems 或者visibleCells 返回值 不是按照你列表的顺序返回的item,你要把这个数组排序。

以swift为例:

 

    func scrollViewDidScroll(_ scrollView: UIScrollView) {if scrollView == cw {let curr = cw.indexPathsForVisibleItems.sorted().first?.section ?? 0if currentTopSection == curr { return }currentTopSection = currindexV.updateStatus(isTouch: false, section: currentTopSection)}}
  相关解决方案