سؤال

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];
    }
}
هل كانت مفيدة؟

المحلول

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.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top