0

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?

4

2 に答える 2

2

deleteRowAtIndexPath:withAnimation:テーブルをどのように表示するかをテーブルに指示するだけです。同時に、実際のデータからこの行を削除する必要があります。別名tableView:NumberOfRowsInSection:、正しい行数を返す必要があります。

于 2013-03-17T12:03:05.307 に答える
0

呼び出し後に元のデータでテーブル ビューをリロードしている可能性がありdeleteRowsAt...ますnumberOfRowsInSection

于 2013-03-17T12:28:06.657 に答える