1

これは私のコードです:SwiftのUILongPressGestureRecognizerを使ってindexPath.rowをタグプロパティに渡すには?

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、デフォルトの1です。私は強くindexPath.row値をmakeItCoolActionに渡す必要がありますが、UIGestureRecognizerにはタグプロパティはありませんが、.viewプロパティにはコードのように表示されることがあります。

私はmakeItCoolAction送信者をUILongPressGestureRecognizerからUIGestureRecogizerに変更しましたが、依然として0値が出力されています。

答えて

0

ビューは、この時点ではゼロです:

cell.addGestureRecognizer(coolGesture) 
coolGesture.view?.tag = 4 
+0

あなたが気正しい:あなたはジェスチャーを追加しましたし、それはこのような見解を持っていた後

coolGesture.view?.tag = 4 

は、タップを設定してみてください!できます! –

関連する問題