Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Trying to understand UITableView's dequeueReusableCellWithIdentifier

Hi everyone:

Say, I have the following code in tableView:cellForRowAtIndexPath:

static NSString* strCellID = @"mycell";
UITableViewCell* pCell = (UITableViewCell*)[tableView dequeueReusableCellWithIdentifier:strCellID];
if(pCell == nil)
{
pCell = [[[UITableViewCell alloc] initWithStyle:UITableViewStylePlain reuseIdentifier:strCellID] autorelease];
}

I have "number of rows" set to 4.

So, my understanding was that if I init a table view cell with one identifier, the next time it will be reused in a call to dequeueReusableCellWithIdentifier: if the same identifier is used. Then why do I get initWithStyle:reuseIdentifier: called 4 times in the example above?

MacBook Pro 17", 2.66 GHz i7, 4GB 1067 DDR3 RAM, OS X 10.6.4 /// iPhone 4, 32GB, iOS 4

Posted on Feb 21, 2011 4:13 PM

Reply
Question marked as Best reply

Posted on Feb 21, 2011 6:28 PM

Cells are reused only after the first "screen" or rows is full. There will always be as many instances of your cell as there are visible cells on screen. Once you scroll, existing cells will be reused to render the data appropriate for that viewport.
1 reply

Trying to understand UITableView's dequeueReusableCellWithIdentifier

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.