Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Embedded UITableView does not detect a swipe to delete row gesture

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.

like image 875
Luke97 Avatar asked Nov 04 '17 21:11

Luke97


2 Answers

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). Subclass UICollectionView and override this method to return true when otherGestureRecognizer 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.

like image 69
Crazyrems Avatar answered Oct 21 '22 10:10

Crazyrems


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...

like image 44
Macistador Avatar answered Oct 21 '22 08:10

Macistador