Using the highlight gesture to select a row

I want to click on each cell to activate push segue, but since view controllerit is always in edit mode, I cannot click on the cells. In editing modeI zoomed reorder controllerin to cover the whole cell, and then made it invisible so that you can drag to reorder tableviewfrom anywhere in the cell, so when I click on cells in edit mode, I actually click on the reorder controller. Please do not tell me to set the tableview property allowsSelectionDuringEditingto YES, as I have already done this, and it still does not allow me to select a cell, because it is covered by the reordering controller that was added to the cell as a subview.

My solution was to prepare a new one push segueusing gestures tapin cell, which would be activated even if the cell was covered with it reorder controller. However, the data that is sent to viewwhich is called segueis always the first cellregardless of which cell I click on. Why is this happening? Any help is appreciated.

this is how i changed my control order

-(void) resizeReorderControl: (UITableView *)tableView reorderCell:(UITableViewCell *)bCell{
    //  Grip customization code goes in here...
    UIView* reorderControl = [bCell huntedSubviewWithClassName:@"UITableViewCellReorderControl"];

    UIView* resizedGripView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetMaxX(reorderControl.frame), CGRectGetMaxY(reorderControl.frame))];
    [resizedGripView addSubview:reorderControl];
    [bCell addSubview:resizedGripView];

    CGSize sizeDifference = CGSizeMake(resizedGripView.frame.size.width - reorderControl.frame.size.width, resizedGripView.frame.size.height - reorderControl.frame.size.height);
    CGSize transformRatio = CGSizeMake(resizedGripView.frame.size.width / reorderControl.frame.size.width, resizedGripView.frame.size.height / reorderControl.frame.size.height);

    //  Original transform
    CGAffineTransform transform = CGAffineTransformIdentity;

    //  Scale custom view so grip will fill entire cell
    transform = CGAffineTransformScale(transform, transformRatio.width, transformRatio.height);

    //  Move custom view so the grip top left aligns with the cell top left
    transform = CGAffineTransformTranslate(transform, -sizeDifference.width / 2.0, -sizeDifference.height / 2.0);

    [resizedGripView setTransform:transform];

    for(UIImageView* cellGrip in reorderControl.subviews)
    {
        if([cellGrip isKindOfClass:[UIImageView class]])
            [cellGrip setImage:nil];
    }
}
+3
source share
1 answer

Here is a solution that works for me.

To find reordering control in iOS7, I changed the code and added another check

-(void) resizeReorderControl: (UITableView *)tableView reorderCell:(UITableViewCell *)bCell{
    ...
    UIView* reorderControl = [bCell huntedSubviewWithClassName:@"UITableViewCellReorderControl"];
        if (!reorderControl) {
            reorderControl = [bCell huntedSubviewWithClassName:@"UITableViewCellScrollView"]; // for iOS7
        }
    ...
    //Then I added my gesture recognizer:
    ...
    UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)];
    tapGestureRecognizer.delegate = self;
    [reorderControl addGestureRecognizer:tapGestureRecognizer];
    ...
}

Add a UIGestureRecognizerDelegatedelegate to the ad manager ad , your view controller interface should look like this:

@interface ViewController <UITableViewDataSource, UITableViewDelegate, UIGestureRecognizerDelegate>

Then we implement the delegate method:

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
    return YES;
}

, UITapGestureRecognizer init:

- (void)handleTap:(UITapGestureRecognizer *)sender {
    NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:[sender locationInView:self.tableView]];
    [self.tableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionNone];
    // If you have custom logic in table view delegate method, also invoke this method too
    [self tableView:self.tableView didSelectRowAtIndexPath:indexPath];
}
+1

All Articles