Iphone UICollectionview项目编号

Iphone UICollectionview项目编号,iphone,objective-c,uicollectionview,Iphone,Objective C,Uicollectionview,我有UIcollectionview和部分。在cellForItemAtIndexPath中,我可以看到indexPath.section和indexPath.item。如何从第一节开始就知道项目的编号?您可能正在查找indexPath。行您需要位于indexPath(0,0)的单元格,因此请尝试: 然后像以前一样使用cellForItemAtIndexPath,没有内置方法。但是,您可以添加所有以前版本的项目数 当前节中项目编号的节: NSInteger num = indexPath.ite

我有
UIcollectionview
和部分。在
cellForItemAtIndexPath
中,我可以看到
indexPath.section
indexPath.item
。如何从第一节开始就知道项目的编号?

您可能正在查找
indexPath。行
您需要位于indexPath(0,0)的单元格,因此请尝试:


然后像以前一样使用
cellForItemAtIndexPath
,没有内置方法。但是,您可以添加所有以前版本的项目数 当前节中项目编号的节:

NSInteger num = indexPath.item;
for (NSInteger section = 0; section < indexPath.section; section++) {
    num += [collectionView numberOfItemsInSection:section];
}
NSInteger num=indexPath.item;
对于(NSInteger section=0;section
但也许你也应该检查一下你是否真的需要这个。例如,如果原因是 您的数据源是一个平面数组,那么您可以考虑重新排列数据源,
反映两级节/项结构。

indexPath.row和indexPath.item是相同的。它们不相同;)导致相同结果的线索(至少我没有体验到任何差异),但最初indexath.row用于UITableView,而.item与UICollectionView一起引入并用于UICollectionView(请参阅)
NSInteger num = indexPath.item;
for (NSInteger section = 0; section < indexPath.section; section++) {
    num += [collectionView numberOfItemsInSection:section];
}