Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

swipe to delete in a UITableView which is embeded in a UIScrollView

I've encountered a problem the same as UIScrollview enable delete row by swipe
It is a tableView and another view work as subViews of a scrollView , and I can't enable "swipe to delete" until I set the scrollEnable property of the scrollView to NO , but it brings another problem : I can't swipe between the tableView and another view
Is there any ways other than setting the scrollEnable property to enable "swipe to delete" ?
If not , when should I set self.scrollEnable = NO, and when should I set self.scrollEnable = YES to have the "swipe to delete" and "swipe between views" both work fine ?

Thank you

like image 939
Bin_Z Avatar asked Dec 01 '22 23:12

Bin_Z


2 Answers

I've successfully used

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer

in a UIScrollView subclass containing the tableview to enable a UISwipeGestureRecognizer residing in the tableview to trigger instead of being swallowed by the "main" scrollview's gesture recognizers.

like image 154
Thor Frølich Avatar answered Dec 05 '22 09:12

Thor Frølich


You need to use custom subclass of UIScrollView. It should works with table views in horizontal scroll views:

@interface MyCoolScrollView : UIScrollView

@end

@implementation MyCoolScrollView

// Allows inner UITableView swipe-to-delete gesture
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRequireFailureOfGestureRecognizer:(nonnull UIGestureRecognizer *)otherGestureRecognizer
{
    return [otherGestureRecognizer.view.superview isKindOfClass:[UITableView class]];
}

@end
like image 23
k06a Avatar answered Dec 05 '22 08:12

k06a