これは私のコードです:
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("cell", forIndexPath: indexPath) as! imageUserCell
let coolGesture = UILongPressGestureRecognizer(target: self, action: #selector(detailedPerson.makeItCoolAction(_:)))
coolGesture.minimumPressDuration = 0.5
coolGesture.view?.tag = 4
cell.addGestureRecognizer(coolGesture)
そして、これは機能コードです:
func makeItCoolAction(sender: UIGestureRecognizer){
print(sender.view?.tag)
print("Photo cooled")
}
コンソールには同じ値が表示されます: 0 がデフォルトです。indexPath.row 値を makeItCoolAction に渡す必要が強くありますが、UIGestureRecognizer にはタグ プロパティがありませんが、コードでわかるように .view プロパティにはタグ プロパティがあります。
makeItCoolAction 送信者を UILongPressGestureRecognizer から UIGestureRecogizer に変更しましたが、それでも 0 の値が出力され続けます。