0

我已经尝试调试这个几个小时了,我还没有看到网上有人遇到同样的问题。

我之前的删除功能按预期工作,然后添加一些代码后,减号按钮神秘地停止工作。起初我以为他们根本不工作,但后来发现如果我按住我的水龙头大约 5 秒钟,它会转动并按应有的方式显示删除按钮。

tableview 上有一些手势,但没有 LongPress 手势。这些单元格是自定义单元格,但是当我第一次使用它时并没有引起问题。任何帮助表示赞赏。以下是相关代码:

///
/// 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];
    }
}
4

1 回答 1

0

我发现评论中建议的点击手势导致了问题。我通过将点击手势设置为 2 次触摸来实现这一点,只是想看看发生了什么。它按预期工作,所以他们一定是互相干扰。

于 2013-04-03T01:34:47.390 回答