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 6159881
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T21:12:23+00:00 2026-05-23T21:12:23+00:00

In my app, i have customize UITableViewCell and is using its contentView property. But

  • 0

In my app, i have customize UITableViewCell and is using its contentView property.
But now the problem is the data in cells are sometimes going in different cells. For example:The data in cell 3 is going into cell 8 or 9 when scroll to the bottom or scroll up.
Here’s the code which iam using in cellForRowAtIndexPath:

- (UITableViewCell *)tableView:(UITableView *)tv cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

    static NSString *CellIdentifier = @"Cell";
    CGFloat fontSize = [UIFont systemFontSize];
    CGFloat smallFontSize = [UIFont smallSystemFontSize];
    UITableViewCell *cell = [tv dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier]autorelease];
        mainLabel = [[[UILabel alloc] initWithFrame:CGRectMake(5,0,150,42)] autorelease];
        mainLabel.font = [UIFont systemFontOfSize:smallFontSize];
        mainLabel.numberOfLines = 3;
        mainLabel.lineBreakMode = UILineBreakModeWordWrap;
        mainLabel.backgroundColor = [UIColor clearColor];
        mainLabel.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleHeight;
        [cell.contentView addSubview:mainLabel];

        secondLabel = [[[UILabel alloc] initWithFrame:CGRectMake(160,0,160,42)] autorelease];
        secondLabel.font = [UIFont systemFontOfSize:smallFontSize];
        secondLabel.numberOfLines = 3;
        secondLabel.lineBreakMode = UILineBreakModeWordWrap;
        secondLabel.backgroundColor = [UIColor clearColor];
        secondLabel.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleHeight;
        [cell.contentView addSubview:secondLabel];


    }
    cell.accessoryType = UITableViewCellAccessoryNone;
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.textLabel.font = [UIFont systemFontOfSize:smallFontSize];
    cell.detailTextLabel.font = [UIFont systemFontOfSize:smallFontSize];
    NSArray * titles = [[NSArray alloc] initWithObjects:@"Project ID", @"Status", @"Approval Date", @"Closing Date", @"Country",@"Region Name", @"Env", @"Team Full Name",@"Borrower", @"Impagency", @"Lending Cost", @"IBRDPlus", nil];

    switch (indexPath.section) {
        case 0:

            mainLabel.text = [titles objectAtIndex:indexPath.row];
            mainLabel.adjustsFontSizeToFitWidth = YES;
            mainLabel.numberOfLines = 4;
            mainLabel.lineBreakMode = UILineBreakModeWordWrap;

            secondLabel.text = [self.basic objectAtIndex:indexPath.row];
            secondLabel.adjustsFontSizeToFitWidth = YES;
            secondLabel.numberOfLines = 4;
            secondLabel.lineBreakMode = UILineBreakModeWordWrap;
            break;
        case 1:

            mainLabel.text = [[self.allSectors objectAtIndex:indexPath.row] valueForKey:@"SECTORNAME"];
            mainLabel.adjustsFontSizeToFitWidth = YES;
            mainLabel.numberOfLines = 4;
            mainLabel.lineBreakMode = UILineBreakModeWordWrap;

            secondLabel.text = [[self.allSectors objectAtIndex:indexPath.row] valueForKey:@"SECTORPCT"];
            secondLabel.adjustsFontSizeToFitWidth = YES;
            secondLabel.numberOfLines = 4;
            secondLabel.lineBreakMode = UILineBreakModeWordWrap;

            break;
        case 2:

            mainLabel.text = [[self.themes objectAtIndex:indexPath.row] valueForKey:@"THEME_NAME"];
            mainLabel.adjustsFontSizeToFitWidth = YES;
            mainLabel.numberOfLines = 4;
            mainLabel.lineBreakMode = UILineBreakModeWordWrap;

            secondLabel.text = [[self.themes objectAtIndex:indexPath.row] valueForKey:@"THEMEPCT"];
            secondLabel.adjustsFontSizeToFitWidth = YES;
            secondLabel.numberOfLines = 4;
            secondLabel.lineBreakMode = UILineBreakModeWordWrap;

            break;

        default:
            break;
    }

    return cell;
}
  • 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-23T21:12:24+00:00Added an answer on May 23, 2026 at 9:12 pm

    This is happening because of this line (which you need to have anyway) :

    UITableViewCell *cell = [tv dequeueReusableCellWithIdentifier:CellIdentifier];
    

    Basically because the cells are being reused the content stays in the cell, therefore you need to clean that cell after dequeu and then set the new contentView.

    What is happen here specifically is that even though you are resetting the text of secondLabel, when you are setting your variable here:

    secondLabel = [[[UILabel alloc] initWithFrame:CGRectMake(160,0,160,42)] autorelease];
    

    The last cell that was created is what secondLabel is pointing to all the time, so you are really always changing the same label, therefore I would suggest something like this:

    UILabel *lblCell;
    for (id label in [cell.contentView subviews]) {
                if ([label isKindOfClass:[UILabel class]]) {
                    lblCell = label;
                }
            }
    
    lblCell.text = [[self.themes objectAtIndex:indexPath.row] valueForKey:@"THEMEPCT"];
    

    Hope that helps.

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

Sidebar

Related Questions

I have an events app which gets events data from sqlite database and displays
I have written this method in objectiveC (for iOS but that immaterial). My app
I have a Rails 3 App using devise. I want to create a User/Profile
In my app i have a slider which i need to customize. I have
I have a Universal App in which I customize my UINavigationBar. In my iPhone
I have a WPF app that handles WM_GETMINMAXINFO in order to customize the Window
I am trying to customize the UITableViewCell below for an iPhone app in a
In my Universal App I have a long UITableView with custom cells..and for some
We have an application which we licence to separate companies. The app is customised
In my app have a window splitted by a QSplitter, and I need to

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.