简体   繁体   English

调用tableView reloadData时出错:更新后现有部分中包含的行数

[英]Getting an error when calling tableView reloadData: The number of rows contained in an existing section after the update

I've seen this error before in people's questions but the only answer I've found is that I should be calling reloadData. 我以前在人们的问题中已经看到过此错误,但是我发现的唯一答案是我应该调用reloadData。 But, that seems to be exactly when I'm getting the error! 但是,这似乎正是我收到错误消息的时间!

So I have a bunch of data for a tableView in an array called itemArray. 所以我在名为itemArray的数组中有大量的tableView数据。 It's empty until a NSURLRequest completes and then when it returns in the number of rows in section 2 is updated to [itemArray count]; 它是空的,直到NSURLRequest完成,然后在返回时将第2节中的行数更新为[itemArray count];

The weird thing is that the error isn't always thrown. 奇怪的是错误并不总是抛出。 Its very intermittent so I'm having trouble isolating what's wrong. 它非常断断续续,所以我很难找出问题所在。

Anyone know a common cause of this error? 有人知道此错误的常见原因吗? I always call reloadData as soon as the datasource changes. 我总是在数据源更改后立即调用reloadData。 Is there any code I can provide that might help you to help me? 我可以提供任何可以帮助您的代码吗?

Exact error: 确切错误:

'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of rows in section 2. The number of rows contained in an existing section after the update (100) must be equal to the number of rows contained in that section before the update (0), plus or minus the number of rows inserted or deleted from that section (0 inserted, 0 deleted) and plus or minus the number of rows moved into or out of that section (0 moved in, 0 moved out).' 'NSInternalInconsistencyException',原因:'无效更新:第2节中的行数无效。更新(100)之后现有节中包含的行数必须等于更新前该节中包含的行数(0 ),加上或减去从该部分插入或删除的行数(已插入0,已删除0),加上或减去移入或移出该部分的行数(移入0,移出0)。

Hard to say without looking at your code, but is the itemArray initialized? 不看代码很难说,但是itemArray是否已初始化? Maybe initialize it in viewDidLoad and see if the errors go away. 也许在viewDidLoad中初始化它,看看错误是否消失了。

You are calling beginUpdates and endUpdates somewhere incorrectly. 您在错误的地方调用了beginUpdatesendUpdates If you are calling reloadData , you should not work with the begin and end updates API. 如果要调用reloadData ,则不应使用开始和结束更新API。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 更新(15)后现有部分中包含的行数必须相等 - number of rows contained in existing section after update (15) must equal 调用tableView.reloadData()时,“致命错误”表明tableView已正确连接 - “fatal error” when calling tableView.reloadData(), the tableView is properly connected 无效更新:执行 TableView.reloadData() 时的节数无效 - Invalid update: invalid number of sections when doing TableView.reloadData() 调用[tableView reloadData]时,TableView无法重新加载 - TableView not reloading when calling [tableView reloadData] 更新tableView中的特定单元格而不调用reloadData - Update Specific cells in a tableView without calling reloadData 在tableview.reloadData之后调用一次函数 - Calling a function once after tableview.reloadData {tableView reloadData} 导致应用在删除部分后崩溃 - {tableView reloadData} causes app to crash after section is deleted 在主线程上调用tableView.reloadData后,UITableView不刷新 - UITableView not refreshing after calling tableView.reloadData on main thread “尝试将第0行插入第0部分,但更新后第0部分只有0行”错误 - “Attempt to insert row 0 into section 0, but there are only 0 rows in section 0 after the update” Error 调用reloadData时,UICollectionView不会立即更新,而是在30-60秒后随机更新 - UICollectionView doesn't update immediately when calling reloadData, but randomly after 30-60 seconds
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM