How to deal with non-visible rows during row deletion. (UITableViews)

前端 未结 1 1391
小蘑菇
小蘑菇 2020-12-18 15:15

I am performing a deletion of several rows of a table. In fact, on this occasion all visible cells are in fact deleted.

This causes the cell immediately below the vi

相关标签:
1条回答
  • 2020-12-18 16:11

    I am not sure I have understood correctly what you mean, but you can try the following.

    NSMutableIndexSet *indexes = [NSMutableIndexSet indexSet];
    

    Each time you delete an object from your model array related to a specific section of the tableView, check if the array count is zero, in which case add an index representing the section to indexes:

    [array removeObjectAtIndex:indexPath.row];
    if(![array count])
        [indexes addIndex: indexPath.section];
    
    Determine all of the indexPaths related to the rows to be deleted, then update the tableView as follows:
    
    [tableView beginUpdates];
    [tableView deleteRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationFade];
    [tableView deleteSections:indexes withRowAnimation:UITableViewRowAnimationFade];
    [tableView endUpdates];
    

    Let me know if this works for you.

    0 讨论(0)
提交回复
热议问题