I have a UICollectionView
with custom cells- They have a UITextView
that mostly covers the entire cell. This presents a problem when using didSelectItemAtIndexPath
. The only way to trigger it is by tapping outside the UITextView
. I want it to trigger wherever in the cell you tap, whether there is a text view or not. How can this be done?
相关问题
- Core Data lightweight migration crashes after App
- How can I implement password recovery in an iPhone
- State preservation and restoration strategies with
- “Zero out” sensitive String data in Swift
- Get the NSRange for the visible text after scroll
相关文章
- 现在使用swift开发ios应用好还是swift?
- UITableView dragging distance with UIRefreshContro
- TCC __TCCAccessRequest_block_invoke
- Where does a host app handle NSExtensionContext#co
- Swift - hide pickerView after value selected
- How do you detect key up / key down events from a
- didBeginContact:(SKPhysicsContact *)contact not in
- Attempt to present UIAlertController on View Contr
I would suggest to use
UIGestureRecognizer
for each cell and when it taped to send it toUITextView
or whatever , perhaps there maybe a better solutions , but I would use this 1 because of simplicity reasons.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 callwhen I'm done with my customised logic in
touchesEnded
.After adding the super call, everything is fine.
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.
didSelectItemAtIndexPath
is called whennone of the subView of collectionViewCell respond to that touch
. As thetextView
respond to those touches, so itwon't forward those touches
to its superView, so collectionView won't get it.override
hitTest:withEvent
method of yourcollectionViewCell
orCollectionView
subclass and always returnself
from them.so it explicitly makes collectionView asfirst responder
.