Note that there are some explanatory texts on larger screens.

plurals
  1. POUITableViewCell background color based upon NSFetchedResultsController - strange issues
    primarykey
    data
    text
    <p>This is driving me absolutely insane.</p> <p>I have a UITableView with cells populated via an NSFetchedResultsController that should have their background color set based upon one of the Core Data parameters.</p> <p>This table view is in the master view of a UISplitViewController and the selected cell needs to remain visibly selected to indicate what is being displayed in the detail view.</p> <p>Based upon guidance from several other Stack Overflow questions, I have learned that the ideal place to configure the cell is during the willDisplayCell delegate call, like this:</p> <pre><code>- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath { WorkTask *workTask = (WorkTask*) [self.fetchedResultsController objectAtIndexPath:indexPath]; if ([workTask.strStatus isEqualToString:@"A"]) { cell.backgroundColor = [self colorWithHexString:@"fffdcf"]; // cell.textLabel.backgroundColor = [self colorWithHexString:@"fffdcf"]; // cell.detailTextLabel.backgroundColor = [self colorWithHexString:@"fffdcf"]; } else if ([workTask.strStatus isEqualToString:@"B"]) { cell.backgroundColor = [self colorWithHexString:@"cfffd1"]; // cell.textLabel.backgroundColor = [self colorWithHexString:@"cfffd1"]; // cell.detailTextLabel.backgroundColor = [self colorWithHexString:@"cfffd1"]; } else if ([workTask.strStatus isEqualToString:@"C"]) { cell.backgroundColor = [self colorWithHexString:@"ffcfcf"]; // cell.textLabel.backgroundColor = [self colorWithHexString:@"ffcfcf"]; // cell.detailTextLabel.backgroundColor = [self colorWithHexString:@"ffcfcf"]; } else { cell.backgroundColor = [self colorWithHexString:@"ffffff"]; // cell.backgroundColor = cell.contentView.backgroundColor; } </code></pre> <p>This mostly sort of works. But...</p> <p>Depending on how I play around with different variants of accomplishing this, I end up with the background color being ignored sometimes (and only sometimes?!?) behind the textLabel and detailTextLabel. Or causing the cell to display incorrectly while selected. Or having the checkmark indicator displayed without a background color. Or having new items added to the core data database showing up in the table, but with the no background color for the cell, but the text labels having a background color. </p> <p>No matter what I do, I have not found a simple and intuitive way to make things behave overall as expected - particularly when cells are being programmatically selected.</p> <p>In fact - the cell selection seems like it might be at the root of the problem. The selected cell is usually the one that ends up drawn incorrectly after I change the selection to another, particularly if the color of the cell changed while the cell was selected.</p> <p>Is there any example out there anywhere of how this is supposed to work?!?!</p> <p>Thanks!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload