Reputation: 10348
This is driving me nuts, I have sections in my UITableView
, but this insertion works when I don't have sections.
Basically I'm doing:
[self.tableView insertRowsAtIndexPaths:array withRowAnimation:UITableViewRowAnimationRight];
I'm getting this error:
The number of sections contained in the table view after the update (5) must be equal to the number of sections contained in the table view before the update (4), plus or minus the number of sections inserted or deleted (0 inserted, 0 deleted).'
I thought it would just work, but this doesn't make sense. What can you guys make of this?
Upvotes: 1
Views: 118
Reputation: 7416
Whenever you make a insertRowsAtIndexPaths:withRowAnimation
call, you also need to modify the data source that backs the table with a similar addition. This ensures that tableView:numberOfRowsInSection:
returns n
before the addition and n+1
after the addition. Anything besides a consistent result with throw the error you described.
Upvotes: 1
Reputation: 385900
You are returning different values from your numberOfSectionsInTableView:
method before and after you send the insertRowsAtIndexPaths:withRowAnimation:
method.
If you are creating an entirely new section in the table view, you must insert it by sending insertSections:withRowAnimation:
message to the table view.
Upvotes: 1