【发布时间】:2014-07-16 17:05:46
【问题描述】:
我在这里看到了一个类似的问题:Reorder cells of UICollectionView。但是,该解决方案涉及覆盖 UICollectionViewFlowLayout 以重新排序单元格。但就我而言,我不想重新排序单元格,而只是相应地转换数据源。
我正在创建一个水平滚动的 UICollectionView。默认情况下,项目从上到下排序:
cell1 cell4 cell7 cell10
cell2 cell5 cell8 cell11
cell3 cell6 cell9 cell12
我对细胞的物理流动很好。但是,我希望我的数据从左向右流动:
data1 data2 data3 data4
data5 data6 data7 data8
data9 data10 data11 data12
只需使用indexPath.item 来确定使用哪些数据不起作用。我必须以某种方式“转换”索引。例如,要显示 cell2 的内容,我需要使用 data5,而不是 data2。
类似的东西:
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
NSInteger index = //Use proper index based on transformed indexPath.item, instead of just indexPath.item
NSDate *cellDate = [self.dateArray objectAtIndex:index]
...
}
关于如何进行这种转变的任何想法?
【问题讨论】:
标签: ios ios7 uicollectionview uicollectionviewlayout