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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T19:09:26+00:00 2026-05-28T19:09:26+00:00

I have customized the cell with four labels, initially it looks fine but when

  • 0

I have customized the cell with four labels, initially it looks fine but when I scroll and then select a cell labels from another row overlaps. here is my code. Any help will be highly appreciated.

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

if (cell == nil) { cell = [[[UITableViewCell alloc]
                            initWithStyle:UITableViewCellStyleDefault 
                            reuseIdentifier: CellIdentifier] autorelease];
}
 NSString *cellIconName = [[self cellIcon] objectAtIndex:[indexPath row]];
cellImage=[UIImage imageNamed:cellIconName];

cell.imageView.image=cellImage;

UILabel *labelOne = [[UILabel alloc]initWithFrame:CGRectMake(65, 10, 140, 20)];
labelOne.text = [[NSString alloc]initWithFormat:@"%@",[dataList objectAtIndex:indexPath.row]];
[cell.contentView addSubview:labelOne];
[labelOne release];

UILabel *labelTwo = [[UILabel alloc]initWithFrame:CGRectMake(260, 10, 140, 20)];
labelTwo.text = [[NSString alloc]initWithFormat:@"%@",[newPrice objectAtIndex:indexPath.row]];
[cell.contentView addSubview:labelTwo];
[labelTwo release];



UILabel *label3 = [[UILabel alloc]initWithFrame:CGRectMake(65, 30, 140, 20)];
label3.text=[[NSString alloc]initWithFormat:@"%@",[details objectAtIndex:indexPath.row]];
[cell.contentView addSubview:label3];
[label3 release];


UILabel *label4 = [[UILabel alloc]initWithFrame:CGRectMake(260, 30, 140, 20)];
label4.text=[[NSString alloc]initWithFormat:@"%@",[oldPrice objectAtIndex:indexPath.row]];
[cell.contentView addSubview:label4];
[label4 release];

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-28T19:09:28+00:00Added an answer on May 28, 2026 at 7:09 pm

    The mistake is you allocated the labels in (else part)outside of the if condition if(cell==nil). You should only create the labels once, when the cell is first created.

    When we run the code the control checks whether the cell is nil or have any values. If we allocate the label in else part every time (while scrolling also) you are creating a new label every time. If we allocate it in if condition, the label is only allocated once for each cell and we just update the text value when scrolling.

    -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
    static NSString *CellIdentifier=@"CellIdentifier";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier: CellIdentifier];
    
    if (cell == nil) 
    { 
    cell = [[[UITableViewCell alloc]
                                initWithStyle:UITableViewCellStyleDefault 
                                reuseIdentifier: CellIdentifier] autorelease];
    
    NSString *cellIconName = [[self cellIcon] objectAtIndex:[indexPath row]];
    cellImage=[UIImage imageNamed:cellIconName];
    
    cell.imageView.image=cellImage;
    
    UILabel *labelOne = [[UILabel alloc]initWithFrame:CGRectMake(65, 10, 140, 20)];
    labelOne.tag = 100;
    [cell.contentView addSubview:labelOne];
    [labelOne release];
    
    UILabel *labelTwo = [[UILabel alloc]initWithFrame:CGRectMake(260, 10, 140, 20)];
    labelTwo.tag = 101;
    [cell.contentView addSubview:labelTwo];
    [labelTwo release];
    
    }
    
    UILabel *labelOne = (UILabel *) [cell.contentView viewWithTag:100];
    labelOne.text = [dataList objectAtIndex:indexPath.row];
    
    UILabel *labelTwo = (UILabel *) [cell.contentView viewWithTag:101];
    labelTwo.text = [newPrice objectAtIndex:indexPath.row];
     
    
    return cell;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have customized UITableViewCell (Static Content Loaded from nib). This cell contains one UILable
I have a UITableview made up with a custom cell loaded from a nib.
I know that if I have some images and subviews added in customized cell
I have customized a UITableViewCell and I want to implement swipe to delete. But
i have an customized cell that is loaded in table view cell and each
Can I have a ListView where I can customize the first cell, and then
we have a very customized UITableViewCell here. So it basically looks like this: +----------------+
I have a class A that inherits UITableViewCell (to customize a table cell). It
In my magento project the search result not displays. I have customized my magento.
We have a lot of customized spreadsheet solutions that are being used and we

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.