Graphics Programs Reference
In-Depth Information
There is one problem: sometimes a UITableView has different types of cells. Occasion-
ally, you have to subclass UITableViewCell to create a special look or behavior.
However, different subclasses floating around the pool of reusable cells create the possib-
ility of getting back a cell of the wrong type. You must be sure of the type of the cell re-
turned to you so that you can be sure of what properties and methods it has.
Note that you don't care about getting any specific cell out of the pool because you're go-
ing to change the cell content anyway. What you need is a cell of a specific type. The
good news is every cell has a reuseIdentifier property of type NSString . When a
data source asks the table view for a reusable cell, it passes a string and says, “I need a
cell with this reuse identifier.” By convention, the reuse identifier is simply the name of
the cell class.
In ItemsViewController.m , update
tableView:cellForRowAtIndexPath: to reuse cells:
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell =
[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
 
Search WWH ::




Custom Search