JSQMessagesViewControllerを使って、メッセージUIを実装しています。
カスタムcellを使って、UITapGestureRecognizerでイベントを設定し、イベントの発火時にtagを取得したいのですが取得方法がわかりません。
swift
1//カスタムcell 2override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { 3 4 let cell = super.collectionView(collectionView, cellForItemAt: indexPath) as! JSQMessagesCollectionViewCell 5 6 let avatarImageTap = UITapGestureRecognizer(target: self, action: #selector(avatarDidTap(sender:))) 7 avatarImageTap.delegate = self 8 cell.avatarImageView?.isUserInteractionEnabled = true 9 cell.avatarImageView?.addGestureRecognizer(avatarImageTap) 10 cell.tag = Int(messages[indexPath.row].senderId)! 11 return cell 12 } 13 14func avatarDidTap(sender: UITapGestureRecognizer) { 15 //この書き方では取得できませんでした 16 print(sender.view?.tag) 17 }
上記がわかる方がおりましたら教えていただけるとありがたいです。
よろしくお願いいたします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/08/23 13:39