【发布时间】:2015-11-09 18:58:33
【问题描述】:
当我点击一个单元格时,我想接收特定于该单元格的索引或其他标识符。该代码有效并进入点击功能。但是我怎样才能收到索引或类似的东西呢?
override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("ShowCell", forIndexPath: indexPath) as UICollectionViewCell
if cell.gestureRecognizers?.count == nil {
let tap = UITapGestureRecognizer(target: self, action: "tapped:")
tap.allowedPressTypes = [NSNumber(integer: UIPressType.Select.rawValue)]
cell.addGestureRecognizer(tap)
}
return cell
}
func tapped(sender: UITapGestureRecognizer) {
print("tap")
}
【问题讨论】:
-
这里有一个解决您确切问题的方法:stackoverflow.com/a/34899415/5815633
标签: swift