I have a UITableView embedded inside of a UICollectionView, the collection view scrolls horizontally so if i try a 'swipe to delete' on one of the table view rows which is inside of a collection view cell, it obviously just scrolls the collection view. Was wondering if there is a work around so that it could detect the swipe on the uitableview part of the collection view cell instead of swiping the uicollection view itself? The UITableView only takes up about a quarter of the collection view cell. I'm using a UIViewController. And i also have paging enabled on my collection view.
Asked
Active
Viewed 588 times
6
-
This function is special TableViewController function. Which Controller are you using? – moxmlb Nov 04 '17 at 22:04
-
UIViewController, thanks for reminding me about that. I'll edit the question – Luke97 Nov 04 '17 at 22:05
-
Have you included the UITableViewDelegate in the Controller? At the top? – moxmlb Nov 04 '17 at 22:06
3 Answers
1
You may use as workaround implementing the hit test like described here for make that the UICollectionView don't get the gestures events when scrolling inside the cell's frame
but IMHO you should not try to break the default behavior and should look to change your UI...

Macistador
- 854
- 12
- 23
1
Try one of the two options:
- Look at
require(toFail otherGestureRecognizer: UIGestureRecognizer)
. Add the swipe gestures with this method to the collection view pan gesture when you create (or populate) the cells. - Try to look at
shouldRequireFailure(of: otherGestureRecognizer)
. SubclassUICollectionView
and override this method to return true whenotherGestureRecognizer
is actually a swipe to delete row gesture.
You just have to figure how you can identify/retrieve both of the gesture recognizers (hint: browse the gestureRecognizers
property to find some PanGestureRecognizers
)
And you should definitely refine that clunky design.

Crazyrems
- 2,551
- 22
- 40
-1
You can try adding a UISwipeGestureRecognizer
to each collection cell and then in it's target action check (gestureRecognizer.state == UIGestureRecognizerStateEnded)
and add your code.

Anushk
- 482
- 4
- 20