M
M
mriddi2013-09-02 16:35:46
Objective-C
mriddi, 2013-09-02 16:35:46

How to define, turn off or rewrite the gesture recognizer responsible for moving cells in the TableView?

The second day I'm trying to solve the following problems:
1. Turning off the gesture recognizer responsible for moving cells in the TableView
2. Making changes to the gesture recognizer responsible for moving cells in the TableView
My application contains three custom classes:
-NDAViewController
-NDATableView(my custom table view)
- NDACell(my custom cell for table view)
I put the NDATableView instance in edit mode (the table is always in this mode):

- (void)viewDidLoad{
[super viewDidLoad];
[myTableView setEditing:YES animated:YES];}

I want to rewrite the method that fires when I drag a cell (swipe on the ReorderControl). To begin with, I tried to determine which recognize gesturer and in which UIView is responsible for this operation. For this I used the method:
-(void) helper:(UIView*) view{
    for (UIView* sub in view.subviews) {
        NSLog(@"%@.subview=%@",NSStringFromClass ([view class]),NSStringFromClass ([sub class]));
        for(UIGestureRecognizer* gestRec in sub.gestureRecognizers)
        {
            NSLog(@"view=%@ gesture recognizer=%@",NSStringFromClass ([sub class]),NSStringFromClass ([gestRec class]));
        }
        [self helper];
    }
}

Thanks to him, I figured out the UIView hierarchy and determined which UIGestureRecognizer each of them has:
1. TableView (has 4 gesture recognizers)
2. Cells (subviews of TableView, has 0 gesture recognizer)
3. UITableViewCellContentView (subview of Cell, has 1 gesture recognizer )
4. UITableViewCellEditControl (subview of Cell, has 0 gesture recognizer)
5. UITableViewCellReorderControl (subview of Cell, has 0 gesture recognizer)
6. UIView x2 (subview of Cell, has 0 gesture recognizer)
I was surprised that UITableViewCellReorderControl doesn't have gesture recognizers. I assumed that one of the four gesture recognizers TableView is responsible for moving the cells. To verify this, I tried to block them using the following method in the ViewController:
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
return NO;};

also assigned 3 gestures(UIGobberGestureRecognizer,
UISwipeGestureRecognizer, UIScrollViewDelayedTouchesBeganGestureRecognize) of TableView - ViewController as a delegate. For UIScrollViewPenGestureRecognizer , you cannot use a ViewController as a delegate. However, moving cells continued to work after that. I tried assigning the same delegate to the UILongPressGestureRecognizer of UITableViewCellContentView but that didn't work either.
Help me figure out which View and its gesture recognizer are responsible for moving cells and how to rewrite their methods.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Storozhev, 2013-09-05
@storoj

maybe it's not the gesture recognizer, but the implementation based on touchesBegin / touchesEnd?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question