2014-10-29 73 views
1

如何从下面的cole中获取项目值?集合视图indexpathforitematpoint项目

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

我目前显示这个,但需要整数值。

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

什么“整数值”?你不明白日志消息的哪一部分?你不知道NSIndexPath是什么?你不知道什么是可选的?这里有什么问题? – matt 2014-10-29 15:15:47

回答

0

我设法得到什么,我需要使用下面的一行:

cellIndexPath?.item 
1

您可以从一个NSIndexPath提取一行。

NSIndexPath.row

您必须确定自己对应于定义的NSIndexPath的编号。 NSIndexPath包含行和列坐标。