Question

I've been at this one for a few days and can't get anything to work (there's some similar questions on SO but none have been quite right/done the trick).

So, I have a UITableView whose cells are subclassed (which are actually UITableViews with sublcassed UITableViewCells). Fundamentally, the table is similar to the one in this tutorial: www.raywenderlich.com/4680/how-to-make-an-interface-with-horizontal-tables-like-the-pulse-news-app-part-1

When I select a cell, I want to change the styling (color specifically) of the subclassed cell to indicate it has been selected (likewise when unselected). I'm not sure how to reloadData for the subclassed cells... I can manipulate the singleton array where the info (indicating if the selected is selected or not) is found so that the cells adjust once the next click occurs.

Example for clarification (s=selected, u=unselected)

Say the table is currently like this

| U | S | S | U |

Now, I want to reset all the cells to unselected (so they should all appear as "U", so I reset the singleton'd array. Obviously the table still is the same. Now, say I select the final cell, this is what I get (which is correct):

| U | U | U | S |

The issue is I want it to be this once the array is reset but before the user selects another cell:

| U | U | U | U |

Sorry if this is unclear; I'll be around to elaborate on anything that may have caused confusion. Thanks SO!

Was it helpful?

Solution

See here. Basically, after you update the state of your array, you need to iterate over visible cells and reconfigure or reload them using one of the techniques described in the link.

OTHER TIPS

Use selectedBackgroundView property of UITableViewCell on cellForRowAtIndexPath:

UIImageView *selBGView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"yourHighlightedImage.png"]];
 cell.selectedBackgroundView = selBGView;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top