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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T21:50:40+00:00 2026-05-31T21:50:40+00:00

I have a UITableView with each cell being broken into several sections with a

  • 0

I have a UITableView with each cell being broken into several sections with a different label in each section. The table gets populated by an NSArray of NSDictionaries which contain all the data that populates the cell’s labels. This part of the UITableView works great.

The problem arises when I change some of the values in one of the NSDictionaries and then reload the table with the updated NSArray. Normally, when I call [myTableView reloadData]; nothing is updated even though (through debugging) I can see the updated data being processed. But if I change the standard: if (cell == nil) { to if (1) {, in the cellForRowAtIndexPath method, then it works beautifully. I understand why if(1) { works but I do not understand why I cannot reuse the cells and just change the label text.

Why does if (cell == nil) not work? Is it a huge resource drain to re-initialize each cell?

CODE:

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

static NSString *cellIdentifier = @"myCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier: cellIdentifier];

if (/*cell == nil*/1) {
    // Initialize Custom Cell
    cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];

    //// Background View
    cellBackgroundView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 622, 43)];
    [cellBackgroundView setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"Images/Library/phase_table_cell.png"]]];

    //// Name Label
    nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 250, 18)];
    [nameLabel setBackgroundColor:[UIColor clearColor]];
    [cellBackgroundView addSubview:nameLabel];

    //// Percent Complete Label
    percentCompleteLabel = [[UILabel alloc] initWithFrame:CGRectMake(300, 10, 30, 18)];
    [percentCompleteLabel setBackgroundColor:[UIColor clearColor]];
    [percentCompleteLabel setTextAlignment:UITextAlignmentCenter];
    [cellBackgroundView addSubview:percentCompleteLabel];

    //// Overall Status Label
    overallStatusLabel = [[UILabel alloc] initWithFrame:CGRectMake(352, 7, 63, 30)];
    [overallStatusLabel setBackgroundColor:[UIColor clearColor]];
    [overallStatusLabel setFont:[UIFont boldSystemFontOfSize:12.0]];
    [overallStatusLabel setLineBreakMode:UILineBreakModeWordWrap];
    [overallStatusLabel setNumberOfLines:2];
    [overallStatusLabel setTextAlignment:UITextAlignmentCenter];
    [cellBackgroundView addSubview:overallStatusLabel];

    //// Finish Date Label
    finishDateLabel = [[UILabel alloc] initWithFrame:CGRectMake(425, 10, 55, 18)];
    [finishDateLabel setBackgroundColor:[UIColor clearColor]];
    [finishDateLabel setTextAlignment:UITextAlignmentCenter];
    [finishDateLabel setFont:[UIFont systemFontOfSize:12.0]];
    [cellBackgroundView addSubview:finishDateLabel];

    //// Overall Weight Label
    overallWeightLabel = [[UILabel alloc] initWithFrame:CGRectMake(505, 10, 30, 18)];
    [overallWeightLabel setBackgroundColor:[UIColor clearColor]];
    [overallWeightLabel setTextAlignment:UITextAlignmentCenter];
    [cellBackgroundView addSubview:overallWeightLabel];

    //// Green Risk View
    greenRiskView = [[UIView alloc] initWithFrame:CGRectMake(557, 4, 61, 10)];
    [greenRiskView setBackgroundColor:[UIColor greenColor]];
    [greenRiskView setHidden:YES];
    [cellBackgroundView addSubview:greenRiskView];

    //// Yellow Risk View
    yellowRiskView = [[UIView alloc] initWithFrame:CGRectMake(557, 17, 61, 10)];
    [yellowRiskView setBackgroundColor:[UIColor yellowColor]];
    [yellowRiskView setHidden:YES];
    [cellBackgroundView addSubview:yellowRiskView];

    //// Red Risk View
    redRiskView = [[UIView alloc] initWithFrame:CGRectMake(557, 30, 61, 10)];
    [redRiskView setBackgroundColor:[UIColor redColor]];
    [redRiskView setHidden:YES];
    [cellBackgroundView addSubview:redRiskView];

    [cell.contentView addSubview:cellBackgroundView];
}

// Get Current Dictionary
NSDictionary *dictForIndexPath = [self.phaseArray objectAtIndex:[indexPath row]];
// Set Elements
[nameLabel setText:[dictForIndexPath objectForKey:@"name"]];
[percentCompleteLabel setText:[dictForIndexPath objectForKey:@"percentComplete"]];
[overallStatusLabel setText:[dictForIndexPath objectForKey:@"overallStatus"]];
[overallWeightLabel setText:[[NSNumber numberWithInt:[[dictForIndexPath objectForKey:@"overallWeight"] intValue]] stringValue]];
//// Create Finish Date String
NSString *finishDateString = [NSString stringWithFormat:@"%@/%@/%@", [dictForIndexPath objectForKey:@"finishDay"], [dictForIndexPath objectForKey:@"finishMonth"], [dictForIndexPath objectForKey:@"finishYear"]];
[finishDateLabel setText:finishDateString];
//// Pick Risk View
NSString *riskColor = [dictForIndexPath objectForKey:@"riskColor"];
if ([riskColor isEqualToString:@"Green"]) {
    [greenRiskView setHidden:NO];
    [yellowRiskView setHidden:YES];
    [redRiskView setHidden:YES];
} else if ([riskColor isEqualToString:@"Yellow"]) {
    [greenRiskView setHidden:YES];
    [yellowRiskView setHidden:NO];
    [redRiskView setHidden:YES];
} else {
    [greenRiskView setHidden:YES];
    [yellowRiskView setHidden:YES];
    [redRiskView setHidden:NO];
}

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-31T21:50:41+00:00Added an answer on May 31, 2026 at 9:50 pm

    Probably you are assigning the value within the if(cell==nil) block? Only the initialization should happen within that block. Move the rest out of it. (Post your complete cellForRow code, if you need more help)

    //edit: now, after you posted your code i see your problem:

    you are storing all your labels and views in member variables.. but of course that only happens, when the if(cell != nil) block is executed. After that, you always access the same single cell (that was assigned last). So you are updating at least one cell 😉

    To fix your problem, work e.g. with tags to get your corresponding views back from the cell. I will show it for your backgroundView, but you have to do it for all of your views (INSTEAD of the member variables. Remove them.)

    static NSString *cellIdentifier = @"myCell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier: cellIdentifier];
    
    if (cell == nil) {
      //// Background View
      UIView* cellBackgroundView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 622, 43)];
      cellBackgroundView.tag = 1;
      [cellBackgroundView setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"Images/Library/phase_table_cell.png"]]];
    }
    
    // get the backgroundview from the current cell
    UIView* backgroundView = [cell.contentView viewWithTag: 1];
    

    and so on..

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

Sidebar

Related Questions

I have a UITableView. The height and content of each cell of the table
I have a UITableView with two sections: free and paid. Each section has a
I've made a UITableView with cells which have different height. On each cell, I've
I have a simple UITableView with two sections. Each section has a header which
I have a table view where I want a different image for each cell
I have a UITableView that displays single large images in each cell. The names
I have a uitableview that loads fairly large images in each cell and the
I have UITextField in each Cell of UITableview and I have added UIPickerview as
I have a UITableView with 3 sections, each returning for numberOfRows the count in
I have a UITableView with 5 UITableViewCells . Each cell contains a UIButton which

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.