Holger Sindbaek
Holger Sindbaek

Reputation: 2344

deleteRowsAtIndexPaths doesn't work

I'm trying to collapse and expand a UITableView section with the help of deleteRowsAtIndexPaths. Nothing seems to happen though and I can't figure out why.

    NSMutableArray *tmpArray = [NSMutableArray array];
    for (int i=1; i<numberOfRowsInSection; i++){
        NSIndexPath *tmpIndexPath = [NSIndexPath indexPathForRow:i inSection:section];
        [tmpArray addObject:tmpIndexPath];
    }

    [_tableView beginUpdates];
    [_tableView deleteRowsAtIndexPaths: tmpArray withRowAnimation:UITableViewRowAnimationAutomatic];
    [_tableView endUpdates];

I've read through a lot of related questions, but nothing I do seem to help.

Any idea of what I'm doing wrong here?

UPDATE

Seems like _tableview is null. I'm guessing that's the main reason nothing is happening. Just don't understand that, since tableview is an outlet and it's already filled with rows and sections.

How can a tableview that's filled with rows and sections be null?

Upvotes: 0

Views: 1865

Answers (2)

ahmad
ahmad

Reputation: 1252

you might be reloading the table view with original data after calling deleteRowsAt... make sure to change update your tableView data source in order to cope with the deleted changes i.e change the number of rows per section in the method numberOfRowsInSection

Upvotes: 0

343max
343max

Reputation: 398

deleteRowAtIndexPath:withAnimation: just tells your table how it should display the table. You need to remove this row from your actual data at the same time. Aka tableView:NumberOfRowsInSection: need to return the correct number of lines.

Upvotes: 2

Related Questions