Re: Reusable Cells
Re: Reusable Cells
- Subject: Re: Reusable Cells
- From: Conrad Shultz <email@hidden>
- Date: Wed, 2 Feb 2011 20:34:48 -0800
On Feb 2, 2011, at 2:42, JD Guzman <email@hidden> wrote:
> Hello,
>
> I'm new to this list and also relatively new to development on the Mac/iPhone platforms.
Welcome!
> I was just wondering if someone could clarify how exactly dequeueReusableCellWithIdentifier: works. The reason I ask is because I have the following code:
>
> ---------
>
> - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
>
> UITableViewCell *cell = [channelList dequeueReusableCellWithIdentifier:@"channelCell"];
>
> if (cell == nil) {
> cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:@"channelCell"] autorelease];
> }
>
> [[cell textLabel] setText:[channels objectAtIndex:[indexPath row]]];
>
> return cell;
> }
>
> ---------
>
> Now if I set a break point inside the if statement I was expecting that it would only be entered once, however it is entered every time a cell is created. Shouldn't the call to dequeueReusableCellWithIdentifier: return a cell after it has been created inside the if statement? Or am I misunderstanding how this works?
What is channelList? Is it just tableView?
Other than that, at first glance this looks ok. Are you sure you are getting a new cell EVERY time? What I mean is: the UITableView will create a pool of cells that covers the visible range of the table, and keep a few around that hang off the ends of the table to help with scrolling performance. I would expect, depending on your row height, etc, for you to break maybe a dozen times before you start seeing cell reuse as you scroll.
Apologies for any mistakes; sent from my iPad as they say.
--
Conrad Shultz
www.synthetiqsolutions.com
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden