Warm tip: This article is reproduced from stackoverflow.com, please click
ios objective-c swift uicollectionview

Check which column a UICollectionView Cell is in?

发布于 2020-04-08 09:27:27

I have a UICollection View and am creating a custom animation when a user taps on a cell.

There are three columns in the collection view. Is there a quick way to figure out, given a index path, the column that was tapped?

Questioner
P. B.
Viewed
83
Paulw11 2020-02-01 07:47

If you have a single section, you can just use modulo arithmetic on the item of the index path.

let column = indexPath.item % 3  // gives a value from 0 to 2