Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of rows in section 6. The number of rows contained in an existing section after the update (0) must be equal to the number of rows contained in that section before the update (9), plus or minus the number of rows inserted or deleted from that section (0 inserted, 3 deleted) and plus or minus the number of rows moved into or out of that section (0 moved in, 0 moved out).'
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'attempt to delete row 2 from section 4 which only contains 0 rows before the update'
大楖是說(shuō)驻谆,numberOfRowsInSection
返回的數(shù)字和 insert / delete
后灸姊,section
所包含的行數(shù)不一致。
在 tableView
的 endUpdates
方法之前锣吼,應(yīng)該對(duì)標(biāo)志變量做處理童漩。endUpdates
后,會(huì)重新刷新 tableView ,numberOfRowsInSection
會(huì)重新被調(diào)用忽冻。
解決方法有兩種:
1, 如上所說(shuō)處理好標(biāo)志變量:
if ([tableView numberOfRowsInSection:4]>2) { }
2痴腌,tableview beginUpdates
之前的行數(shù)對(duì)應(yīng)的是前一個(gè)數(shù)據(jù)源雌团,開(kāi)始reloadcell
時(shí)tableview
并不知道數(shù)據(jù)源發(fā)生了變化
[tableview reloadData]