1. 程式人生 > >ios 解決bug(2)---invalid number of rows in section 0. The number of rows contained。。。

ios 解決bug(2)---invalid number of rows in section 0. The number of rows contained。。。

在做UItableview的刪除時,報錯原因如下

invalid number of rows in section 0.  The number of rows contained in an existing section after the update (8) must be equal to the number of rows contained in that section before the update (8), plus or minus the number of rows inserted or deleted from that section (0 inserted, 1 deleted) and plus or minus the number of rows moved into or out of that section (0 moved in, 0 moved out).'


檢查後是由於刪除section時多寫了兩個section刪除語句,導致section的索引出錯。

解決辦法,將其中的一個刪除語句註釋掉就行

 [tableView deleteSections:[NSIndexSet indexSetWithIndex:1] withRowAnimation:UITableViewRowAnimationLeft];