Tom Coomer
Tom Coomer

Reputation: 6547

Collection view indexpathforitematpoint item

How do I get the item value from the cole below?

let pointInTable: CGPoint = sender.convertPoint(sender.bounds.origin, toView: self.collectionView)
let cellIndexPath = self.collectionView?.indexPathForItemAtPoint(pointInTable)
println(cellIndexPath)

I am currently shown this but need the integer value.

Optional(<NSIndexPath: 0xc000000000000016> {length = 2, path = 0 - 1})

Upvotes: 1

Views: 442

Answers (2)

Tom Coomer
Tom Coomer

Reputation: 6547

I managed to get what I needed by using the line below:

cellIndexPath?.item

Upvotes: 0

David Ansermot
David Ansermot

Reputation: 6112

You can extract the row from a NSIndexPath.

NSIndexPath.row.

You have to determine yourself the number corresponding to a defined NSIndexPath. NSIndexPath contains row and col coordinates.

Upvotes: 1

Related Questions