我有UIcollectionview
與部分。在cellForItemAtIndexPath
我可以看到indexPath.section
和indexPath.item
。我如何知道第一節開頭的項目號碼?UICollectionview項目編號
0
A
回答
2
沒有內置的方法。但你可以在當前部分中的所有先前 部分項目的數量增加了項目編號:
NSInteger num = indexPath.item;
for (NSInteger section = 0; section < indexPath.section; section++) {
num += [collectionView numberOfItemsInSection:section];
}
不過,或許你也應該檢查你是否真的需要這一點。例如,如果原因是 您的數據源是平面陣列,那麼您可以考慮重新排列數據源 ,以反映兩級部分/項目結構。
-1
您可能正在尋找indexPath.row
。
0
您需要在indexPath(0,0)的細胞,所以嘗試:
NSIndexPath * indexPath = [NSIndexPath indexPathForItem: 0 inSection: 0];
,然後用cellForItemAtIndexPath
像以前
相關問題
- 1. 選擇項目以編程方式UICollectionView
- 2. 移動UICollectionView項目
- 3. UICollectionView雙重項目
- 4. 如何按項目編號項目編號
- 5. 奇數numberOf項目在UICollectionVIew
- 6. 密碼python項目編號
- 7. SOAP Method Max項目編號
- 8. 選擇項目編號
- 9. Apache poi項目符號和編號
- 10. Silverlight中的項目符號和編號
- 11. Eclipse Android項目編號目標可用
- 12. 如何在另一個UIViewController中編輯UICollectionView項目?
- 13. 不能在UICollectionView選擇項編程
- 14. UICollectionView總是一個項目後面
- 15. 刪除indexPathsForSelectedItems中的所有項目,UICollectionView
- 16. Swift - UICollectionView連續顯示多個項目
- 17. UICollectionView項目刪除引發異常
- 18. UICollectionView動畫(插入/刪除項目)
- 19. uicollectionview:設置具體項目數量爲
- 20. 防止UICollectionView中的項目「打包」
- 21. UICollectionView滾動到一個項目
- 22. 用選定的編號保存項目
- 23. jQuery自動完成編號和項目
- 24. Extjs 4設置每個項目編號
- 25. 獲取體式項目編號
- 26. 使用prev()查找項目編號?
- 27. ms項目:wbs編號重置問題
- 28. mdDialog通過編號選擇項目
- 29. Android - 通過編號查找項目
- 30. 檢索Joomla 2.5組件項目編號
indexPath.row和indexPath.item是相同的。 – Alexey
他們是不一樣的;)導致相同的結果(至少我沒有經歷任何區別),但最初indexPath.row用於UITableViews和.item引入並用於UICollectionViews(請參閱[這裏的詳細信息] (https://developer.apple.com/library/ios/documentation/uikit/reference/NSIndexPath_UIKitAdditions/Reference/Reference.html) – HAS