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
1 reply

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

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 Account.