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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T12:51:02+00:00 2026-05-21T12:51:02+00:00

I am creating grouped table in my application. It works fine. But when I

  • 0

I am creating grouped table in my application.
It works fine. But when I scroll the table upward and backward reprinted text on previous cell. It look like horrible.

This is my Code

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

    UITableViewCell *cell = [tableView  dequeueReusableCellWithIdentifier:@"cellID"];

    if (!cell)
    {
        cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:@"cellID"] autorelease];  
    }
 /*
    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    */

    if(indexPath.section == 0)
    {
        cell.backgroundColor = [UIColor clearColor];
        cell.accessoryType = UITableViewCellAccessoryNone;

        float rowHeight = [DetailViewController calculateHeightOfTextFromWidth:[dict objectForKey:@"golf_name"] :[UIFont boldSystemFontOfSize:18] :290 :UILineBreakModeTailTruncation];

        UILabel *categorName = [[UILabel alloc] initWithFrame:CGRectMake(20, 5, 290, rowHeight)];
        categorName.font = [UIFont boldSystemFontOfSize:20];
        categorName.numberOfLines = 5;
        categorName.backgroundColor = [UIColor clearColor];
        categorName.textColor = [UIColor whiteColor];
        categorName.text = [dict objectForKey:@"golf_name"];
        [cell addSubview:categorName];
        [categorName release];
    }
    if(indexPath.section == 1)
    {
        cell.backgroundColor = [UIColor whiteColor];
        cell.accessoryType = UITableViewCellAccessoryNone;

        UILabel *categorName = [[UILabel alloc] initWithFrame:CGRectMake(50, 10, 70, 20)];
        categorName.font = [UIFont boldSystemFontOfSize:15];
        categorName.numberOfLines = 5;
        categorName.backgroundColor = [UIColor clearColor];
        categorName.textColor = [UIColor colorWithRed:145.0f/255.0f green:162.0f/255.0f blue:184.0f/255.0f alpha:1];
        categorName.text = @"Phone";
        [cell addSubview:categorName];
        [categorName release];

        UILabel *phone = [[UILabel alloc] initWithFrame:CGRectMake(110, 10, 290, 20)];
        phone.font = [UIFont boldSystemFontOfSize:15];
        phone.numberOfLines = 5;
        phone.backgroundColor = [UIColor clearColor];
        //categorName.textColor = [UIColor colorWithRed:145.0f/255.0f green:162.0f/255.0f blue:184.0f/255.0f alpha:1];
        phone.text = [dict objectForKey:@"golf_phone"];
        [cell addSubview:phone];
        [phone release];
    }
    if(indexPath.section == 2)
    {
        cell.backgroundColor = [UIColor whiteColor];
        cell.accessoryType = UITableViewCellAccessoryNone;

        UILabel *categorName = [[UILabel alloc] initWithFrame:CGRectMake(20, 10, 90, 20)];
        categorName.font = [UIFont boldSystemFontOfSize:15];
        categorName.numberOfLines = 5;
        categorName.backgroundColor = [UIColor clearColor];
        categorName.textColor = [UIColor colorWithRed:145.0f/255.0f green:162.0f/255.0f blue:184.0f/255.0f alpha:1];
        categorName.text = @"Home page";
        [cell addSubview:categorName];
        [categorName release];

        UILabel *phone = [[UILabel alloc] initWithFrame:CGRectMake(110, 10, 230, 20)];
        phone.font = [UIFont boldSystemFontOfSize:15];
        phone.numberOfLines = 5;
        phone.backgroundColor = [UIColor clearColor];
        //categorName.textColor = [UIColor colorWithRed:145.0f/255.0f green:162.0f/255.0f blue:184.0f/255.0f alpha:1];
        phone.text = [dict objectForKey:@"golf_url"];
        [cell addSubview:phone];
        [phone 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-21T12:51:03+00:00Added an answer on May 21, 2026 at 12:51 pm

    Update

    My original answer was not the correct way to reuse UITableViewCell’s. You should never use “CellID%d%d”(indexPath.row & indexPath.column) as cell identifier, that defeats the very purpose of cell reuse. It will create separate UITableViewCell for every row in the table, and every one of those cells stays in memory. Imagine what will happen if you have a tableView with around 1000 rows.

    The real answer to OP’s question is – make sure to reset a UITableViewCell returned by dequeueReusableCellWithIdentifier because it might return a cell that is already used and its UI populated. For example, if you didn’t reset the texts in UILabel, it might contain strings that should have been shown in a different row of your tableView.

    My original Answer (Don’t use this)

    Hiren, just try,

    UITableViewCell *cell = [tableView  dequeueReusableCellWithIdentifier:[NSString stringWithFormat:@"CellID%d%d",indexPath.section,indexPath.row]];
    if (!cell){
     cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:[NSString stringWithFormat:@"CellID%d%d",indexPath.section,indexPath.row]] autorelease];  
    }
    

    instead of

    UITableViewCell *cell = [tableView  dequeueReusableCellWithIdentifier:@"cellID"];
    if (!cell)
    {
       cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:@"cellID"] autorelease];  
    }
    

    Please read this..you will understand how to give cell identifiers..

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

Sidebar

Related Questions

I'm working on creating a grouped table view. The data is being loaded alright,
What is the easiest way of creating an UISwitch inside a grouped table view
I'm creating a report with a table that is grouped by a department code.
I want to create grouped table as dynamically. My aim is creating sections as
When creating a web application, and lets say you have a User object denoting
I'm creating a custom UITableViewCell , similar in style to UITableViewCellStyleValue1 but with an
I am interested in creating a form in an iphone application similar to this
Creating a patch is very easy in SubVersion, With Tortoise, you right-click and select
Creating hashes of hashes in Ruby allows for convenient two (or more) dimensional lookups.
Creating Traversals for Binary Search Tree with Recursion. void inOrder(void (*inOrderPtr)(T&)) { if(this->left !=

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.