When reloading a UITableView section, all sections blink

I am using UITableViewController , and using:

 [self.tableView reloadSections:[NSIndexSet indexSetWithIndex:sectionNumber] withRowAnimation:UITableViewRowAnimationNone]; 

to reload a separate part of the table (to animate the insertion of new cells). The problem is that all partitions and their cells flash white instantly every time this call is made. This does not happen if I use

 [self.tableview reloadData]; 

but happens no matter what line animation I use.

I know that I can use insertRowsAtIndexPaths:withRowAnimation: but I currently have a race condition that prevents me from using this. I’ll fix it at some point, but in the meantime I would like to know why all the cells in the sections blink when I reload one section. Also, if I can turn off the flash and just animate the insertion / deletion of cells, that would be ideal.

+6
source share
2 answers

I believe that it blinks because when you reload a specific partition, it should still recalculate the size of all visible partitions. Hence the flash. Without using insert / delete (because he knows that the table will only change by one), you will not be able to get past this.

If you are just trying to do this in the simulator, it is possible that the flash will either disappear or become less noticeable when loading on the device itself.

0
source

Maybe it's too late. But it can help someone.

Obj-C:

 [UIView performWithoutAnimation:^{ [self.tableView reloadSections:[NSIndexSet indexSetWithIndex:[indexPath section]] withRowAnimation:UITableViewRowAnimationNone]; }]; 

Swift 5:

  UIView.performWithoutAnimation { self.tableView.reloadSections(NSIndexSet(index: indexPath.section), with: .none) } 
0
source

Source: https://habr.com/ru/post/958114/


All Articles