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'
大楖是說,numberOfRowsInSection
返回的數(shù)字和 insert / delete
后,section
所包含的行數(shù)不一致。
在 tableView
的 endUpdates
方法之前,應(yīng)該對標(biāo)志變量做處理。endUpdates
后,會重新刷新 tableView ,numberOfRowsInSection
會重新被調(diào)用。
解決方法有兩種:
1, 如上所說處理好標(biāo)志變量:
if ([tableView numberOfRowsInSection:4]>2) { }
2,tableview beginUpdates
之前的行數(shù)對應(yīng)的是前一個數(shù)據(jù)源,開始reloadcell
時tableview
并不知道數(shù)據(jù)源發(fā)生了變化
[tableview reloadData]