當我點擊一個單元格時,我想要接收特定於該單元格的索引或其他標識符。代碼工作並進入輕擊功能。但是,我怎樣才能得到一個索引或類似的東西?點擊單元格並獲得索引
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")
}
有一個解決您的確切問題在這裏:http://stackoverflow.com/a/34899415/5815633 – Uriel