简体   繁体   中英

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?

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.

您可能在调用deleteRowsAt...后重新加载具有原始数据的表视图deleteRowsAt...确保更改更新您的tableView数据源以便处理已删除的更改,即更改方法numberOfRowsInSection每个部分的行数

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM