↓で、collectionViewCell上にあるボタンをタップした際のcellのindexpathを取得できたのですが、
UILongPressGestureRecognizerで同様なことを行おうとした場合のロングプレスしたボタン判別の記述方法がわかりません。
swift
1@IBAction func fileMenuButtonTapped(_ sender: UIButton) { 2 let indexPath: IndexPath = fileNavigatorCollectionView.indexPath(for: sender.superview!.superview as! UICollectionViewCell)! 3 let fileName = items[indexPath.item] 4 5 print("indexPath:",indexPath) 6 print("fileName:",fileName) 7 }
同じことをボタンをロングプレスした際に行えないでしょうか?
sender: UIButton
swift
1@IBAction func fileMenuButtonLongTapped(_ sender: UILongPressGestureRecognizer) { 2 if(sender.state == UIGestureRecognizerState.began) { 3 4 } else if (sender.state == UIGestureRecognizerState.ended) { 5 let indexPath: IndexPath = fileNavigatorCollectionView.indexPath(for: tappedButton.superview!.superview as! UICollectionViewCell)! 6 7 print("indexPath:",indexPath) 8 print("fileName:",fileName) 9 } 10 } 11
セルの長押しは他の処理で使用する予定のため、設置したボタン長押しで該当セルのインデックスパスを取得したいです。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2018/01/19 10:08