didEndEditingRowAtIndexPath收到nil

时间:2011-06-28 00:52:41

标签: objective-c uitableview

我正在试图弄清楚我的桌面视图发生了什么。当我在编辑模式下删除一行时,它可以顺利运行,但是当滑动到删除模式时,它就会崩溃。

我在每个函数中都设置了断点,并且comitEditingStyle: atIndexPathdidEndEditingRowAtIndexPath: indexPath从有效对象更改为nil

-(void)tableView:(UITableView *)tableView willBeginEditingRowAtIndexPath:(NSIndexPath *)indexPath
{
    editFromSwipe = YES;
    [tableView setEditing:YES animated:YES];
}

-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle 
                                          forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if(editingStyle == UITableViewCellEditingStyleInsert)
    {
        [self addNewNoteToGroup:[NSNumber numberWithInt:[indexPath section]]];
    }
    else if(editingStyle == UITableViewCellEditingStyleDelete && !editFromSwipe)
    {
        [[noteGroupsList objectAtIndex:[indexPath section]] deleteNoteAtIndex:[indexPath row]];

    }
}

-(void)tableView:(UITableView *)tableView didEndEditingRowAtIndexPath:(NSIndexPath *)indexPath
{
    [notesTable deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationRight];
    editFromSwipe = NO;
    [tableView setEditing:NO animated:YES];
}

1 个答案:

答案 0 :(得分:1)

通常的方法是从“commit”方法调用[notesTable deleteRowsAtIndexPaths:...,因为它应该删除行。可能会假设该行已被删除,因此旧索引路径不再有效,因此didEndEditing ...具有nil索引路径。

(IIRC文档还说你不打算在“提交”中更改编辑状态,所以你仍然需要didEndEditing。)