0

I've been trying to debug this for hours now and I haven't seen anyone online that's having the same issue.

I had the delete function working as expected previously, then after adding some code, mysteriously the minus buttons stopped functioning. At first I thought they weren't working at all but then figured out that if I held my tap for about 5 seconds, it would turn and display the delete button like it should.

There are some gestures on the tableview, but no LongPress gestures. The cells are custom cells, but that didn't cause an issue when I first had it working. Any help is appreciated. Here's the relevant code:

///
/// Pushes detail view for item swiped
///
- (IBAction)cellSwipeLeft:(UISwipeGestureRecognizer *)sender {
    if (sender.state == UIGestureRecognizerStateEnded && ![self isEditing]) {
        NSIndexPath *gestureIndexPath = [self modelIndexPathForIndexPath:[self indexPathForUIGestureRecognizer:sender]];

        // swiped left
    }
}

///
/// Checks off reminder in list
///
- (IBAction)cellSwipeRight:(UISwipeGestureRecognizer *)sender {
    if (sender.state == UIGestureRecognizerStateEnded && ![self isEditing]) {
        NSIndexPath *gestureIndexPath = [self modelIndexPathForIndexPath:[self indexPathForUIGestureRecognizer:sender]];

        //swiped right
    }
}

- (IBAction)cellTap:(UITapGestureRecognizer *)sender {

    if (sender.state == UIGestureRecognizerStateEnded && ![self.tableView isEditing]) {
    NSIndexPath *gestureIndexPath = 
     [self modelIndexPathForIndexPath:[self indexPathForUIGestureRecognizer:sender]];

       // push detail view
    }
}

///
/// Makes tableview rows editable
///
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath     {
    return YES;
}

///
/// Returns editing style of tableview
///
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView     editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
    return UITableViewCellEditingStyleDelete;
}

///
/// Toggles tableview editing
///
- (void)setEditing:(BOOL)editing animated:(BOOL)animated {

    [super setEditing:editing animated:animated];
    [self.tableView setEditing:editing animated:animated];
}

///
/// Deletes selected rows
///
- (void)tableView:(UITableView *)tableView
commitEditingStyle:(UITableViewCellEditingStyle)editingStyle
 forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (editingStyle == UITableViewCellEditingStyleDelete)
    {
        [self deleteReminderAtIndexPath:indexPath];

        //  Animate deletion
        NSArray *indexPaths = [NSArray arrayWithObject:indexPath];
        [[self tableView] deleteRowsAtIndexPaths:indexPaths
                            withRowAnimation:UITableViewRowAnimationAutomatic];
    }
}
3
  • Why are you using a tap recognizer instead of – tableView:didSelectRowAtIndexPath: ? Can you show how you set up the gesture recognizers? Apr 3, 2013 at 1:01
  • Thanks! That pointed me in the right direction in figuring out the tap gesture issue. Although I can't get the didSelectRowAtIndexPath: to work very well either. A simple tap on the cell doesn't call that method. I'll be looking into that next Apr 3, 2013 at 1:36
  • You have to set the UITableView delegate property to your view controller. Apr 3, 2013 at 1:37

1 Answer 1

0

I figured out that the tap gesture, as suggested in the comments was causing the issue. I realized this by setting the tap gesture to 2 touches, just to see what happened. It worked as expected, so they must've been interfering with each other.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.