Denis Balko
Denis Balko

Reputation: 1596

deleteRowAtIndexPath does not actually delete the row

trying to delete a row from UITableView and everything works fine except when I am deleting the last row left (at index 0,0) in which case I get an error saying

The number of sections contained in the table view after the update 
(0) must be equal to the number of sections contained in the table
view before the update (1), plus or minus the number of sections
inserted or deleted (0 inserted, 0 deleted).'

This occurs right after it reaches

[tableView endUpdates];

which is right after the delete rows function.

Any idea why does the deleteRowsAtIndexPaths function not work? I checked the indexPath and it is showing 0,0 just as it should.

Thanks

Upvotes: 0

Views: 237

Answers (1)

Grzegorz Krukowski
Grzegorz Krukowski

Reputation: 19792

After you delete a row you should make sure your method:

 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView

Returns proper amount of sections - in your case if you delete a row, sections should remain the same - and according to error you are decreasing the value returned by that function.

Also this method

 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

Must return proper values (which is row - 1) after deleting one row.

Paste more code so we can identify where the problem is exactly.

Upvotes: 1

Related Questions