我有UIcollectionview
部分。在cellForItemAtIndexPath
我可以看到indexPath.section
和indexPath.item
。我怎么知道第一节开头的项目编号?
答案 0 :(得分:2)
没有内置方法。但您可以添加以前所有项目的数量 当前部分中项目编号的部分:
NSInteger num = indexPath.item;
for (NSInteger section = 0; section < indexPath.section; section++) {
num += [collectionView numberOfItemsInSection:section];
}
但也许你也应该检查一下你是否真的需要这个。例如,如果原因是 您的数据源是一个扁平数组,那么您可能会考虑重新排列数据源, 反映两级部分/项目结构。
答案 1 :(得分:0)
您需要indexPath(0,0)处的单元格,因此请尝试:
NSIndexPath * indexPath = [NSIndexPath indexPathForItem: 0 inSection: 0];
然后像以前一样使用cellForItemAtIndexPath
答案 2 :(得分:-1)
您可能正在寻找indexPath.row
。