不细说了,知道情景的看看:
在设置索引条与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)}}