Ok, here is how I think this works:
Using dequeueReusableCellWithIdentifier for tableView, you can significantly speed up the process. Instead of creating an instance of many cells, you simply create an instance as many as necessary, i.e. As many as visible (this is processed automatically). If you scroll to an area in the list where there are "cells" that have not yet received their visual representation, instead of creating new ones, you reuse existing ones.
You can try it yourself by following these steps:
static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; NSLog(@"new one"); } else { NSLog(@"old one"); }
Remember that you want dequeueReusableCellWithIdentifier to return the cell, if applicable. Therefore, if the cell is to be reused, make sure that it is correct for the situation. What are reuseIdentifiers for? Usually you only need one. But there may be a list that uses several different types of cells, in which case you will have to keep them separate, providing different reuseIdentifiers. Otherwise, you can get the cell that you consider as some other cell (for example, the UITableView cell, and not the one you wanted).
Basically, as I understand it, use different reuseIdentifiers for different types of cells, where kind means class. If you use only standard cells, you probably only need one re-identifier.
This design pattern is known as a combination of objects .
quano Feb 15 '10 at 23:36 2010-02-15 23:36
source share