0

I have a NSMutableArray with a list of prizes.

With those, I filled a UITableView.

Now, I´m trying to delete one of those prizes using TableView CommitEditingStyle. And giving me the "Invalid update: invalid number of sections...." error.

I readed a lot of post over internet about the "Invalid update: invalid number of sections...." but I can´t make it work.

First I remove the object from the array and then update the TableView (like all the posts teach me). But still give me the error

I try setting the array to nill and is the same.

Is necesary to refresh the array or something like this?

This is my Code:

-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{


if (editingStyle == UITableViewCellEditingStyleDelete)
{
    [[self myPrizesList] removeObjectAtIndex: [indexPath row]];

    [self.tableView beginUpdates];              

    // Either delete some rows within a section (leaving at least one) or the entire section.
    if ([[self myPrizesList] count] > 0)
    {
        // Section is not yet empty, so delete only the current row.
        [self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]
                         withRowAnimation:UITableViewRowAnimationFade];
    }
    else
    {
        // Section is now completely empty, so delete the entire section.
        [self.tableView deleteSections:[NSIndexSet indexSetWithIndex:indexPath.section] 
                 withRowAnimation:UITableViewRowAnimationFade];
    }

    [self.tableView endUpdates];
}

}

I always said that, for a 5 element array, "the number of sections contained in the table view after the update (5) must be equal to the number of esctions contained in the table view before the update (5), plus or minus the number of sections inserted or deleted (0 insert, 1 deleted)"

If I set the array to nil, say: "the number of sections contained in the table view after the update (1) must be equal to the number of esctions contained in the table view before the update (1), plus or minus the number of sections inserted or deleted (0 insert, 1 deleted)"

Thanks and sorry for my poor english

6
  • please post more code, if you can the whole class Commented Nov 29, 2011 at 16:00
  • 1
    Please include your numberOfSections and numberOfRowsInSection methods, it is the disconnect between these and the operation you are doing in the method above that is causing your problem. Commented Nov 29, 2011 at 16:01
  • 1
    @owengerig - not the whole class, please, no! Commented Nov 29, 2011 at 16:01
  • filertomeetthe15charequirement: :P Commented Nov 29, 2011 at 16:03
  • 2
    also @Mark Comix please work on your acceptance rating, maybe go back and mark some questions as answered Commented Nov 29, 2011 at 16:04

1 Answer 1

1

It is the sections deletion that is the issue, you are deleting the final prize AND section, but when the table reloads it still has the original number of sections... 5. How are you determining the number of sections to return? This needs to reduce if you have deleted one.

Sign up to request clarification or add additional context in comments.

1 Comment

i thought this was going to be the problem. 1 up (as if u need the points). you should be using [tableArray count] Mark, or whatever is the name of your array

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.