简体   繁体   中英

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. 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. 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];

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. 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).'

Hard to say without looking at your code, but is the itemArray initialized? Maybe initialize it in viewDidLoad and see if the errors go away.

You are calling beginUpdates and endUpdates somewhere incorrectly. If you are calling reloadData , you should not work with the begin and end updates API.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM