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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T14:48:12+00:00 2026-06-04T14:48:12+00:00

hi guys i have a normal UITableViewController with some cell inside, i have just

  • 0

hi guys i have a normal UITableViewController with some cell inside,
i have just 1 cell that has this property:

cell.backgroundColor = [UIColor lightGrayColor];

it show me a gray color on a cell (good).

The problem comes when i use the scroller, (i tap on the window and i go down for see
other cells) in this case the Gray color of the cell move (insanely) from the Position where it was
to another cell.

why ??

the code:

static NSString *CellIdentifier = @”Cell”;

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}

if(cell.backgroundColor == [UIColor lightGrayColor])
{
   cell.backgroundColor = [UIColor lightGrayColor];
}
else
{
   cell.backgroundColor = [UIColor clearColor];
}
switch (currentStatus) {
    case KBI_NAME:
    {
        switch (indexPath.section) {
            case 0:
            {
                if(indexPath.row == 0)
                {
                    if (currentUser.currentKBI != nil && ![currentUser.currentKBI isEqualToString:@""]) {
                        cell.textLabel.text = currentUser.currentKBI;
                    }
                    else{
                        cell.textLabel.text = @"asdf";
                    }  

                    cell.userInteractionEnabled = NO;

                    cell.backgroundColor = [UIColor lightGrayColor];
                }
                if(indexPath.row == 1)
                {
                    cell.textLabel.text = @"xyz";
                    cell.textLabel.textAlignment = UITextAlignmentCenter;
                }

                break;
            }
            case 1:
  • 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-06-04T14:48:14+00:00Added an answer on June 4, 2026 at 2:48 pm

    When you scroll in a UITableView, cells that are scrolled out of view are reused for cells that scroll into view. That’s what the following line is for:

    cell = [tableView dequeueReusableCellWithIdentifier:@"cellIdentifier"];
    

    So if this line returns a cell, you need to set the background color every time because you might have gotten the cell with the gray background.

    if (isGrayCell)
        cell.backgroundColor = [UIColor lightGrayColor];
    else
        cell.backgroundColor = [UIColor clearColor];
    

    Update

    Your code for setting the background color doesn’t make sense. If the recycled cell has a gray background, you set it to gray again even if you need a different color. Those like should look something like this:

    if(currentStatus == KBI_NAME && indexPath.row == 0)
    {
       cell.backgroundColor = [UIColor lightGrayColor];
    }
    else
    {
       cell.backgroundColor = [UIColor clearColor];
    }
    

    Update 2

    It’s probably much easier, if you simply initialize the cell every time:

    cell.backgroundColor = [UIColor clearColor];
    

    If you need a gray background, the color is later changed again to gray.

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

Sidebar

Related Questions

Thus far you guys have been wildly helpful with me getting this little ditty
guys i have arrays in which i have to match this kind of text
Guys i have a WebView in my Screen with some TextFields in it. Whenever
Guys, I have a C# Winforms application with a panel inside the form. What
Can you guys show me how to get this ERD in 5th normal form?
hey guys, i have a form that can be influenced with up and down
Here is what I'm trying to do: I have a normal form with some
hey guys, i have a certain plugin on my website that adds a inline
hey guys, I have an input field that looks for matched characters on a
Hey guys I would like to save some time....is there a form generator that

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.