UICollectionView didSelectItemAtIndexPath not called when tapped on UITextView

前端 未结 6 1525
傲寒
傲寒 2021-02-13 05:13

I have a UICollectionView with custom cells- They have a UITextView that mostly covers the entire cell. This presents a problem when using didSel

相关标签:
6条回答
  • 2021-02-13 05:51

    Do you override touchesEnded: withEvent: ?

    I had the same problem today and I found that I have some customised logic in touchesEnded in one of collectionview's container views, and I didn't call

     [super touchesEnded: withEvent:]
    

    when I'm done with my customised logic in touchesEnded.

    After adding the super call, everything is fine.

    0 讨论(0)
  • 2021-02-13 05:51

    Select UITextView, in that specific case UICollectionViewCell, and switch to attribute inspector. The uncheck User interaction enabled and it should work fine.

    0 讨论(0)
  • 2021-02-13 06:00

    I ran into this problem when I had a scroll view taking up my entire collection view cell. While all the solutions above probably work fine, I came up with my own elegant work-around. I put a 'select' label under my scroll view. Since the label is not part of the scroll view, it passes the tap event on to the collection view. It also serves as a nice indicator that an action is required of the user.

    0 讨论(0)
  • 2021-02-13 06:05

    I would suggest to use UIGestureRecognizer for each cell and when it taped to send it to UITextView or whatever , perhaps there maybe a better solutions , but I would use this 1 because of simplicity reasons.

    0 讨论(0)
  • 2021-02-13 06:05

    Just do this

    textview.isUserInteractionEnabled = false 
    
    0 讨论(0)
  • didSelectItemAtIndexPath is called when none of the subView of collectionViewCell respond to that touch. As the textView respond to those touches, so it won't forward those touches to its superView, so collectionView won't get it.

    override hitTest:withEvent method of your collectionViewCell or CollectionView subclass and always return self from them.so it explicitly makes collectionView as first responder.

    0 讨论(0)
提交回复
热议问题