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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:31:27+00:00 2026-05-25T13:31:27+00:00

I have a tableView where I add UILabel’s to cell contentView as subview in

  • 0

I have a tableView where I add UILabel’s to cell contentView as subview in cellForRowAtIndexPath method like this:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *CellIdentifier = @"ReuseCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

if(cell == nil ){
    cell =[[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
}
// Code to remove labels overlay
for(UIView* view in cell.contentView.subviews){
    if ([view isKindOfClass:[UIView class]]) {
        [view removeFromSuperview];
    }
}
if ([indexPath row]<[itemsArray count]){
    UILabel* label1 = [[UILabel alloc] initWithFrame:CGRectMake(10,18,280,10)];
    label1.text = [NSString stringWithFormat:@"Description %@",[[itemsArray objectAtIndex:[indexPath row]] valueForKey:@"Desc"]];
            label1.font = [UIFont fontWithName:@"Helvetica" size:14];
    [cell.contentView addSubview:label1];
    [label1 release];

    UILabel *label2 = [[UILabel alloc] initWithFrame:CGRectMake(10,25,280,10)];
    label2.text = [NSString stringWithFormat:@"Price %@",[[itemsArray objectAtIndex:[indexPath row]] valueForKey:@"Price"]];
    label2.font = [UIFont fontWithName:@"Helvetica" size:14];
    [cell.contentView addSubview:label2];
    [label2 release];

    UILabel *label3 = [[UILabel alloc] initWithFrame:CGRectMake(10,40,290,11)];
    label3.text = [NSString stringWithFormat:@"Loc %@",[[itemsArray objectAtIndex:[indexPath row]] valueForKey:@"Loc"]];
    label3.font = [UIFont fontWithName:@"Helvetica" size:14];
    [cell.contentView addSubview:label3];
    [label3 release];
}
return cell;

}

When I scroll table view UILabels overlap on previous one’s because of cell reuse so I remove it using:

// Code to remove labels overlay
    for(UIView* view in cell.contentView.subviews){
        if ([view isKindOfClass:[UIView class]]) {
            [view removeFromSuperview];
        }

Which is why my scrolling is not so smooth if there are many rows to display. How to make my scrolling smooth ?

  • 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-25T13:31:28+00:00Added an answer on May 25, 2026 at 1:31 pm

    Don’t remove the labels: reuse them. If you give each one a tag, you can retrieve them using the content view’s -viewWithTag: and just change their text.

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        static NSString *CellIdentifier = @"ReuseCell";
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    
        UILabel *label1;
        UILabel *label2;
        UILabel *label3;
        if( cell == nil )
        {
            cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
    
            label1 = [[UILabel alloc] initWithFrame:CGRectMake(10,18,280,10)];
            label1.font = [UIFont fontWithName:@"Helvetica" size:14];
            label1.tag = 1;
            [cell.contentView addSubview:label1];
            [label1 release];
    
            label2 = [[UILabel alloc] initWithFrame:CGRectMake(10,25,280,10)];
            label2.font = [UIFont fontWithName:@"Helvetica" size:14];
            label2.tag = 2;
            [cell.contentView addSubview:label2];
            [label2 release];
    
            label3 = [[UILabel alloc] initWithFrame:CGRectMake(10,40,290,11)];
            label3.font = [UIFont fontWithName:@"Helvetica" size:14];
            label3.tag = 3;
            [cell.contentView addSubview:label3];
            [label3 release];
        }
        else
        {
            // retrieve the labels using the tags you defined earlier
    
            label1 = (UILabel *)[cell.contentView viewWithTag:1];
            label2 = (UILabel *)[cell.contentView viewWithTag:2];
            label3 = (UILabel *)[cell.contentView viewWithTag:3];
        }
    
        if ( [indexPath row] < [itemsArray count] )
        {
            NSDictionary *item = [itemsArray objectAtIndex:[indexPath row]];
            label1.text = [NSString stringWithFormat:@"Description %@", [item valueForKey:@"Desc"]];
            label2.text = [NSString stringWithFormat:@"Price %@", [item valueForKey:@"Price"]];
            label3.text = [NSString stringWithFormat:@"Loc %@", [item valueForKey:@"Loc"]];
        }
    
        return cell;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In a tableview I have on every cell a UILongPressGestureRecognizer which I add like
This is my cellForRowAtIndexPath UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) {
So, I have implemented this method to add a footer to my table view:
I'm trying to add a subview to a tableview cell and of course using
I have a tableview that has groups. I would like to add a dummy
I have very custom TableView like Add Contact View in iPhone's Contacts. I like
In my application i want to add activity indicator under UItableview where tableview will
I have UITableView with Custom View on it. For the bottom of the tableview,
I've a UITableView which when a cell has the same content that other, this
I have a tableView where the user can add contacts to. These contacts get

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.