2011-05-20 63 views
0

HII每一個問題刪除分組表

我用下面的代碼rgouped表視圖

- (void)tableView:(UITableView *)tv commitEditingStyle:(UITableViewCellEditingStyle)editingStyle 
forRowAtIndexPath:(NSIndexPath *)indexPath { 

    if(editingStyle == UITableViewCellEditingStyleDelete) { 

     //Get the object to delete from the array. 
     insertUpdateDelete *objInsertUpdateDelete = [appDelegate.arrObjects objectAtIndex:indexPath.row]; 
     [appDelegate DeleteRecord:objInsertUpdateDelete]; 

     //Delete the object from the table. 
     [tableView1 deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade]; 
    } 
} 


    } 

刪除行,但其在該行

[tableView1 deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade]; 
崩潰的行

崩潰日誌是:

2011-0 5-20 19:21:20.233 IICS [10744:207] *斷言故障 在 - [UITableView的 _endCellAnimationsWithContext:],/SourceCache/UIKit_Sim/UIKit-1448.89/UITableView.m:995 2011-05-20 19:21:20.235 IICS [10744:207]

*** Terminating app due to uncaught exception 

'NSInternalInconsistencyException', 原因:無效更新:在第0。 數包含在後 現有段的行的無效 數量的行更新(3) 必須等於行數 co在 更新(3)前加上或減去插入或刪除 節(插入0個,刪除1個)的行的編號爲 。

任何哥們都可以幫我嗎? thanx

回答

1

確保您的數據源反映您在致電deleteRowsAtIndexPaths:之前所做的更改。我看到你打電話給[appDelegate DeleteRecord:objInsertUpdateDelete];,但是如果你的數據源沒有直接從appDelegate獲取它的記錄,並且可能從你的類中的一個數組中獲取它們,你還需要從該數組中刪除它。

作爲一個便箋,您使用應用程序委託的設計模式可能就像一個「泥巴球」。 Is it good practice to use AppDelegate for data manipulation and Handling?

0

您需要先檢查您要刪除的行是否爲某一節中的唯一一行。

+0

實際上我不需要刪除每一節中的所有第一行,因爲我加載到該節的每一行的數據來自sqlite數據庫表的單行 – Ravi 2011-05-20 14:15:22

+0

我不認爲所以。他從3行開始,刪除後仍有3行。這在第0節發生,但這是無關緊要的。 – Rayfleck 2011-05-20 14:19:45

0

看着你的方法:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 

難道此方法始終返回正確的行數?看起來你不會從任何數據源支持你的部分中刪除該行。

編輯: 您可能正在執行刪除操作,但在您的表的dataSource請求新的rowcount時尚未完成(或已提交)。你可能需要延遲你的[tableView deleteRowsAtIndexPath:]直到數據庫提交。