简体   繁体   中英

Flushing UITableView queue for cells

我想知道是否有人可以回复我,如果在调用UITableView reloadData时UITableView队列被刷新。我正在尝试这样做,这不是帮助我。任何建议?

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

If you want to manually flush queued cells in way that may change with the implementation, you can do so in ugly manner, like so:

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

Hope this helps...

Once the table is loaded, the cells are reused. Reloading the table does not flush the queue. reloadData calls - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;

In this method the if(cell==nil) condition is present so that cells are not flushed once they have been 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 are using an accessoryView

cell.accessoryView = nil;

Also take a look at this example. UITableView not updating correctly when scrolling.

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