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

  • Home
  • SEARCH
  • 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 6868163
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:24:01+00:00 2026-05-27T03:24:01+00:00

in my iPhone app I’m using an UITableView with custom cells. These cells contain

  • 0

in my iPhone app I’m using an UITableView with custom cells. These cells contain different labels, mainly just representing text. But I’m using one of the labels as some sort of status indicator, by giving it different colors.
Since the scrolling became pretty slow I wanted to reuse the cells. Doing that gives me a good performance boost but the “status label” is beeing displayed wrong. The colors are not correct anymore for the different cells (All other labels are correct).

Anyone has experienced such problems and can give me a hint?

Edit:
The code for the custom tablecell

- (void)setIncident:(Incident *)_incident{
[self setSelectionStyle:UITableViewCellEditingStyleNone];
incident = _incident;

streamNameLbl.text = incident.streamName;
jobNameLbl.text = incident.jobName;
workInProgressByLbl.text = incident.workInProgressBy;
NSDateFormatter *tempFormatter = [[NSDateFormatter alloc] init];
[tempFormatter setDateFormat:@"hh:mm"];
errorTimeLbl.text = [NSString stringWithFormat:@"%@", [tempFormatter stringFromDate:incident.errorTime]];

[tempFormatter setDateFormat:@"dd. MMM"];
plandateLbl.text = [NSString stringWithFormat:@"%@", [tempFormatter stringFromDate:incident.planDate]];

returnCodeLbl.text = [@"RC: " stringByAppendingString: incident.returnCode];
runNumberLbl.text = [@"Run: " stringByAppendingString: incident.runNumber];
severityLbl.text = incident.severity;
restartStatusLblValue.text = incident.restartStatus;

    NSString * color = incident.severityColor;
    NSString * colorR = [color substringWithRange:NSMakeRange(1, 2)];
    NSString * colorG = [color substringWithRange:NSMakeRange(3, 2)];
    NSString * colorB = [color substringWithRange:NSMakeRange(5, 2)];

    unsigned intColorR = 0;
    unsigned intColorG = 0;
    unsigned intColorB = 0;

    NSScanner *scanner = [NSScanner scannerWithString:colorR];
    [scanner scanHexInt:&intColorR];
    scanner = [NSScanner scannerWithString:colorG];
    [scanner scanHexInt:&intColorG];
    scanner = [NSScanner scannerWithString:colorB];
    [scanner scanHexInt:&intColorB];

    incidentStatusLbl.backgroundColor = [UIColor clearColor];

    CAGradientLayer *gradient = [CAGradientLayer layer];
    gradient.frame = incidentStatusLbl.bounds;
    gradient.startPoint = CGPointMake(0, 0.5);
    gradient.endPoint = CGPointMake(1, 0.5);
    UIColor * startColor = [UIColor colorWithRed:1 green:1 blue:1 alpha:1];
    UIColor * endColor = [UIColor colorWithRed:intColorR/255.0 green:intColorG/255.0 blue:intColorB/255.0 alpha:1];
    gradient.colors = [NSArray arrayWithObjects:(id)[startColor CGColor], (id)[endColor CGColor], nil];

    [incidentStatusLbl.layer insertSublayer:gradient atIndex:0];
}

cellForRowAtIndexPath in the UITableView

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

incidentCell = (IncidentCell *)[tableView dequeueReusableCellWithIdentifier:@"IncidentCell"];
if (incidentCell == nil) {
    NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"IncidentCell" owner:self options:nil];
    incidentCell = [nib objectAtIndex:0];
     NSLog(@"Loading cell from xib file");
    }
else{
    NSLog(@"Reusing cell");    
     }

NSMutableArray *sectionDetails = ((NSMutableArray *)[incidentDic objectForKey:[self.sortedSections objectAtIndex:[indexPath section]]]);

Incident *incident = [sectionDetails objectAtIndex:[indexPath row]];

[incidentCell setIncident:incident];

return incidentCell;
}
  • 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-27T03:24:01+00:00Added an answer on May 27, 2026 at 3:24 am

    As you are reusing cells, when a cell is asked in - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath it is not reloaded from your nib.
    So if you set the label color to black in the nib for example, and you do in your code

    if (some_condition) {
       cell.myLabel.textcolor= myStatusColor;
    }
    

    when a label has a myStatusColor color once, it will keep it when you’ll reuse it.

    So you’ll have to do

    if (some_condition) {
       cell.myLabel.textcolor= myStatusColor;
    } else {
       cell.myLabel.textcolor= [UIColor black];
    }
    

    In fact your problem come from [incidentStatusLbl.layer insertSublayer:gradient atIndex:0];

    If you use it once, you’ll have a subLayer, (let’s call it subLayer1). When you’ll reuse your cell, you’ll add another sublayer at index 0, BEHIND subLayer1. You may want to remove your old custom subLayer before.

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

Sidebar

Related Questions

My iPhone app formats an NSDecimalNumber as a currency using setCurrencyCode, however another screen
My iPhone App has custom buttons that display png-images. I like to replace the
My iphone app getting json data from php server. 2 basic questions, just to
My iphone App shows a table view having list of 6000 items. (these items
In iPhone App i am using core Plot vertical bar chart. How to Remove
In iPhone App I want to send Image and Text together in single Email
My iPhone app's core data model is changing and I have a custom mapping
my iphone app is using soap web-services. I want to know how it would
My iPhone app is using encrypted assets. The decryption key will need to be
The iphone app I am creating has an array of commonly used settings. These

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.