代码:
func addGroupTopicItem(groupTopicItem:GroupItem) { if !self.existedGroupTopic(groupTopicItem.id) { dispatch_async(dispatch_get_main_queue(), { () -> Void in self.groupTopicItemList.append(groupTopicItem) let insertedRowIdx = self.groupTopicItemList.count – 1 let curRealRowNum = self.tableView.numberOfRowsInSection(0) } |
‘NSInternalInconsistencyException’, reason: ‘Invalid update: invalid number of rows in section 0. The number of rows contained in an existing section after the update (50) must be equal to the number of rows contained in that section before the update (50), plus or minus the number of rows inserted or deleted from that section (1 inserted, 0 deleted) and plus or minus the number of rows moved into or out of that section (0 moved in, 0 moved out).’ |
搜:
swift tableView.endUpdates NSInternalInconsistencyException Invalid update: invalid number of rows in section 0
ios – Invalid update: invalid number of rows in section 0 – Stack Overflow
ios – ‘Invalid update: invalid number of rows in section 0 – Stack Overflow
ios – Invalid update: invalid number of rows in section – Stack Overflow
NSInternalInconsistencyException(Invalid update: invalid number of rows in section 0) – ios
ios – Reload Table view cell with animation (Swift) – StackOverflow
swift insertRowsAtIndexPaths NSInternalInconsistencyException
ios – NSInternalInconsistencyException in insertRowsAtIndexPaths – Stack Overflow
去改为:
self.tableView.beginUpdates() self.groupTopicItemList.append(groupTopicItem) let insertedRowIdx = self.groupTopicItemList.count – 1 let insertedRowIndexPath:NSIndexPath = NSIndexPath(forRow: insertedRowIdx, inSection: 0) self.tableView.insertRowsAtIndexPaths([insertedRowIndexPath], withRowAnimation: UITableViewRowAnimation.Bottom) self.tableView.endUpdates() |
结果:
有时候还是会出错:
‘NSInternalInconsistencyException’, reason: ‘Invalid update: invalid number of rows in section 0. The number of rows contained in an existing section after the update (4) must be equal to the number of rows contained in that section before the update (4), plus or minus the number of rows inserted or deleted from that section (1 inserted, 0 deleted) and plus or minus the number of rows moved into or out of that section (0 moved in, 0 moved out).’ |
最后还是无法解决,最终暂时用了:
self.tableView.reloadData()
。。。
转载请注明:在路上 » 【基本解决】swift中tableView.endUpdates再次出现NSInternalInconsistencyException Invalid update: invalid number of rows in section 0