2013-10-08 39 views
0

試圖從UITableView刪除一行,一切工作正常,當我刪除了最後一排左(at index 0,0)在這種情況下,我得到一個錯誤說deleteRowAtIndexPath實際上並沒有刪除該行

The number of sections contained in the table view after the update 
(0) must be equal to the number of sections contained in the table 
view before the update (1), plus or minus the number of sections 
inserted or deleted (0 inserted, 0 deleted).' 

這之後發生除它達到了

[tableView endUpdates]; 

這就是刪除行函數之後。

任何想法爲什麼deleteRowsAtIndexPaths函數不起作用?我檢查了indexPath,它顯示0,0就像它應該。

感謝

+1

我覺得在刪除特定部分的最後一行時,您必須減少部分數量。 –

回答

1

你刪除行後,你應該確保你的方法:

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 

返回段適量 - 在你的情況,如果你刪除一行,段應保持不變 - 和根據錯誤你正在減少該函數返回的值。刪除一行後 -

同樣在此方法

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

必須返回合適的值(1,其爲一行)。

粘貼更多代碼,以便我們可以確定問題的確切位置。

+0

哦,不,非常感謝,我剛纔意識到這些部分是問題,不知道爲什麼我將這個錯誤作爲行的問題讀取。非常感謝 –

相關問題