Clearing UITableView Queue for Cells

I was wondering if anyone could answer me if the UITableView queue turns red when the UITableView reloadData is called. I am trying to do this and it does not help me. All offers?

+4
source share
2 answers

if you look at the header file for a UITableView, you will see that there is a private NSMutableDictionary (iVar) called "_reusableTableCells". This is a dictionary with cell reuse identifiers as a key and an array with cells that are currently off screen as a value.

If you want to manually clear the cells in the queue, which may change with the implementation, you can do it ugly, for example:

NSMutableDictionary *cells = (NSMutableDictionary*)[self.tableView valueForKey:@"_reusableTableCells"]; [cells removeAllObjects]; 

Hope this helps ...

+8
source

After loading the table, the cells are reused. Rebooting the table does not reset the queue. reloadData calls - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;

This method has an if(cell==nil) condition if(cell==nil) , so that the cells are not cleared after they are loaded into memory and, therefore, reused.

To get around this, you reset your cells before applying the correct information.

 cell.detailTextLabel.text = @""; cell.accessoryType = UITableViewCellAccessoryNone; 

Or if you use accessoryView

 cell.accessoryView = nil; 

Also consider this example. UITableView does not update correctly when scrolling.

+4
source

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


All Articles