Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6924097
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:37:11+00:00 2026-05-27T10:37:11+00:00

I’m rewriting some code to improve tableview performance. I’m trying to implement the dequeueReusableCellWithIdentifier

  • 0

I’m rewriting some code to improve tableview performance. I’m trying to implement the dequeueReusableCellWithIdentifier but not having much luck.

When a cell moves off screen and back on again, it’s contents are duplicated (each time it goes off and back into screen). The contents of the cell are also appearing in other cells when they shouldn’t be.

It seems to me the content needs clearing when the cell is reused but I can’t figure it out.

The cells themselves consist of 4 CUSTOM image buttons and 4 labels, in a row:

[ ]  [ ]  [ ]  [ ]
abc  abc  abc  abc

Some cells might have all these images/labels populated, others might only have 1 or 2.

Code below..

- (UITableViewCell *)tableView:(UITableView *)thetableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    //NSString *CellIdentifier = [NSString stringWithFormat:@"Cell",indexPath.section];
    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
    }
    else
    {
        //Tried this to clear old contents but doesn't make a difference
        for (HomeScreenButton* b in cell.subviews)
        {
            NSLog(@"RemovedOldButton");

            b = nil;
        }
        for (UILabel* b in cell.subviews)
        {
            NSLog(@"RemovedOldLabel");

            b = nil;
        }
    }
    cell.accessoryType = UITableViewCellAccessoryNone;
    cell.selectionStyle = UITableViewCellSelectionStyleNone;

    int section = indexPath.section;


    NSMutableArray *sectionItems = [sections objectAtIndex:section]; //Gets the array of objects for this section 
    if (sectionItems.count == 0) return cell;

    LepidEntity * le = [sectionItems objectAtIndex:0];// Gets the object for this section (family/group etc.)


    if (([le.type isEqualToString:@"family"]) || ([le.type isEqualToString:@"group"]))
    {
        NSMutableArray * tmpAnn;
        int annCount = 0;
        //Get annotations for this family/group
        if ([le.type isEqualToString:@"family"])
        {
            Family * family = (Family *)le;
            tmpAnn = [[NSMutableArray alloc]initWithArray:family.annotations];
        }
        else
        {
            Group * group = (Group *)le;
            tmpAnn = [[NSMutableArray alloc]initWithArray:group.annotations];

        }
        annCount = tmpAnn.count;
        //We want to start at the last item in the array. indexPath.row*4. First row would be 0 then 4, then 8 etc.
        for (int i = indexPath.row*4;i < tmpAnn.count;i++)
        {
            Annotation * theAnnotation = [tmpAnn objectAtIndex:i];
            CGRect bRect = CGRectMake(i*80, 5, 80, 80);
            HomeScreenButton *button = [self getResultsViewButton:bRect imagePath:theAnnotation.image cellForRowAtIndexPath:indexPath i:i entity:theAnnotation];
            [button addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
            [cell.contentView addSubview:button];
            [button release];
            button = nil;
            //Get and configure the label
            CGRect lRect = CGRectMake(i*80, 80, 100, 16);
            UILabel *label = [self getResultsViewLabel:lRect text:theAnnotation.name cellForRowAtIndexPath:indexPath i:i];
            [cell.contentView addSubview:label];
            [label release];
            label = nil;
        }
    }
    else
    {
        Species * s;
    }

    return cell;}

-(HomeScreenButton *) getResultsViewButton:(CGRect)rect imagePath:(NSString *)image 

    cellForRowAtIndexPath:(NSIndexPath *)indexPath i:(int)i entity:(LepidEntity *)entity
    {
        HomeScreenButton *button=[[HomeScreenButton alloc] initWithFrame:rect];

        image = [image stringByReplacingOccurrencesOfString:@"Images/" withString:@"Thumbs/"];

        UIImage *buttonImageNormal=[UIImage imageWithContentsOfFile:GetFullPath(image)];//imageNamed:image];
        [button setBackgroundImage:buttonImageNormal forState:UIControlStateNormal];
        [button setContentMode:UIViewContentModeCenter];
        NSString *tagValue = [NSString stringWithFormat:@"%d%d", indexPath.section+1, i];
        button.tag = [tagValue intValue];
        button.entity = entity;
        return button;
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T10:37:12+00:00Added an answer on May 27, 2026 at 10:37 am

    You should call [b removeFromSuperview] instead of setting it to nil.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.