What does this method means?

i dont understand this part

// To improve performance, this method first checks // for an existing cell object that we can reuse // If there isn't one, then a new cell is created UITableViewCell *c = [self.taskTable dequeueReusableCellWithIdentifier:@"Cell"];

even with the comment explanation in the code I don’t really know where the @“Cell” came from.
Can someone tell me how they reuse the cell if the cell is empty? and what does @“Cell” mean?

The @“Cell” is a string. It’s used to identify a kind of cell. For example, let’s say you have a table. That table has 2 sections, one for rows that show text, and one for rows that show a block of color. You could create 2 kinds of cells, and give one “an identifier” (sort of like a name or tag or easy way to mark the cell type). You give one an identifier of @“TextCell” and the other @“ColorCell”. Then when your method to draw the cells occurs, you can easily make each cell type just by calling it’s identifier:

UITableViewCell *c = [self.taskTable dequeueReusableCellWithIdentifier:@“TextCell”];
or
UITableViewCell *c = [self.taskTable dequeueReusableCellWithIdentifier:@“ColorCell”];

In the code sample you quote, there is only one kind of cell type, so it’s just given a default name of @“Cell”. If you make the cell in code you would give it an identifier when it’s made, if you make it in IB I believe there is a field where you can label the identifier there also.

Cells are re-used when they go off-screen. So they are “emptied” of their contents and re-used as “new” cells when the table view scrolls. As in my Text/Color scenario, again a dequeued cell is cleared and the table needs to pick which kind of old/empty cell it needs to display. Thus the identifier for kind of cell to reuse.

HTH

Hi CPaveglio,
Then can you tell me what this code does?

//Tell the table view which class to instantiate whenever it needs to create a new cell [self.taskTable registerClass:[UITableViewCell class] forCellReuseIdentifier:@"Cell"];

I don’t really understand what the “CLASS” class method does even after reading the developer documentation.
It says

[quote]Returns the class object.

  • (Class)class[/quote]

What does returns class object even mean?

Also , I can roughly understand your explanation above but those stuff wasn’t explained in detail in the book. Will it be covered Big Nerd Ranch iOS programming book? Also the protocol stuff really does bugs me also as I have no idea what each protocol does I mean I don’t know What protocol to use and what method to put into the required protocol and what parameter of protocol i can use. I’ll show you an example.

[code]- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
// To improve performance, this method first checks
// for an existing cell object that we can reuse
// If there isn’t one, then a new cell is created
UITableViewCell *c = [self.taskTable dequeueReusableCellWithIdentifier:@“Cell”];

// Then we (re)configure the cell based on the model object,
// in this case the tasks array, ...
NSString *item = [self.tasks objectAtIndex:indexPath.row];
c.textLabel.text = item;

// ... and hand the properly configured cell back to the table view
return c;

}
[/code]

the code is using the indexPath parameter in the method and I have no idea why. Will protocol be covered also in their next book? thanks

What does returns class object even mean?
[/quote]
Every class has a unique object (only one) called its class object. If you have the class object of a class, then you can use it to create instances of that class.

The following code tells the table view object to use UITableViewCell’s class object whenever it wants to create UITableViewCell objects named “Cell”:

...
[self.taskTable registerClass:[UITableViewCell class] forCellReuseIdentifier:@"Cell"];
...

And the following code tells the table view to find a free cell named “Cell” and reuse it. If there is no such free cell, then the table view asks the class object, the class object of UITableViewCell (see above), to create a new cell object:

UITableViewCell *aCell = [self.taskTable dequeueReusableCellWithIdentifier:@"Cell"];
...

Now that make sense. Why wasn’t that explanation added into the book.
Thanks by the way.