Search code examples
iphoneiosxcodeuitableviewcell

How to update UITableViewCell drawing


My app displays some news in a UITableView. For each news-topic, the background color of the UITableViewCell is different (added a UIView in my custom cell).

So far, it works. But If I press on a UIBarButton to deselect one news-category, the content changes, but the background stays the same as before.

The color does not change, because the cell does not reload again after button click.

Any ideas?

Thank you!


Solution

  • You can set the color for the cell in (as per your logic):

    - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath

    This will make sure the color is set every time the cell is displayed.