UICollectionView页面滑动reloadData之后,Sections里的cell顺序变乱。
模仿原生的IOS的calendar写一个程序。年份表示使用UICollectionView。 UICollectionView页面滑动reloadData之后,Sections里的cell顺序变乱。 开始的时候,顺序是正确的。 当向上或向下滚动的时候。月份的顺序就会变乱。 下面是代码 数据源的代码 // 定义展示的Section的个数 func numberOfSections(in collectionView: UICollectionView) -> Int { return _years.count; } // 定义展示的UICollectionViewCell的个数 func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { return _years[section].months.count; } //每个UICollectionView的头部 func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView { if kind == “UICollectionElementKindSectionHeader”{ let indexYear = _years[indexPath.section]; […]