1

これは私のコードです:

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 の値が出力され続けます。

4

1 に答える 1

0

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

coolGesture.view?.tag = 4

ジェスチャを追加した後にタップを設定してみてください。次のようなビューが表示されます。

cell.addGestureRecognizer(coolGesture)
coolGesture.view?.tag = 4
于 2016-04-27T19:45:17.390 に答える