2012-04-26 68 views
-1

這是我的代碼,它應該刪除選定的行。它導致應用程序崩潰,因爲它聲稱行數不正確。我查了一下,這是不正確的;表中的行已被刪除,但顯然行數沒有更新(代碼確實被打)......這怎麼可能? (我有另一個UITableViewController與確切的代碼,它的工作原理)。我如何解決它?UITableView:爲什麼刪除後「行數」沒有被更新?

if (editingStyle == UITableViewCellEditingStyleDelete) { 

    // remove row from the table 
    SQLite *sql = [[SQLite alloc] init]; 
    [sql deleteReadingsRow: indexPath.row]; 

    // Delete the row from the data source 
    [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade]; 
} 

這裏是確定的行數的代碼:

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

    SingletonListOfReadings *rShareInstance = [SingletonListOfReadings sharedInstance]; 

    return rShareInstance.listOfReadings.count; // Return the number of rows in the section 
} 

回答

0

我發現這是不被複位時的行是問題...我依靠單(SingletonListOfReadings)在d/b表中刪除。

0

雖然你發現你的問題,你應該看看使用NSFetchedResultsController來代替。幾乎沒有工作,它可以在添加,刪除或修改行時自動更新表格。一般來說,它是一個更可靠的解決方案,而不是依靠保持單身人士同步。有很多使用表格的例子。

相關問題