2011-06-28 30 views
0

我想弄清楚我的表格視圖發生了什麼。當我在編輯模式下刪除一行時,它可以順利運行,但是當刪除模式滑動時,它會崩潰。didEndEditingRowAtIndexPath得到零

我在每個功能並以某種方式和有效的對象nilindexPath變化之間comitEditingStyle: atIndexPathdidEndEditingRowAtIndexPath:設置斷點。

-(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

的常用方法是調用從「承諾」的方法[notesTable deleteRowsAtIndexPaths:...,因爲它就是我們應該刪除行。可能有一個假設,該行已被刪除,所以舊的索引路徑不再有效,所以didEndEditing ...有一個nil索引路徑。

(IIRC的文檔也說,你是不是要更改「提交」編輯狀態,所以你仍然需要didEndEditing。)

+0

這是我在做什麼,但它總是崩潰,所以我我認爲我做錯了,回到我認爲的文檔... – Clay