Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

theprizerevealed

macrumors regular
Original poster
Feb 26, 2016
183
12
hi,

I have TableViewController in my app with an embedded Navigation Controller. When I wish to return to the TableViewController by using the back button then the cell will no longer deselect automatically in the latest version of iOS as it did before. Can someone tell me what the code might be to deselect a highlighted cell and where should I place it? Basically I want the highlighting to disappear. Currently, it stays highlighted.

I have read some suggestions on various websites but they don't seem to work me. Thanks for your help.
 

xStep

macrumors 68020
Jan 28, 2003
2,031
143
Less lost in L.A.
Use deselctRow or setSelected in viewWillAppear or viewDidAppear.

If only one row is selected use indexPathForSelectedRow to get its index.
 

theprizerevealed

macrumors regular
Original poster
Feb 26, 2016
183
12
Maybe I'm explaining this the wrong way. To highlight the cell I was changing the background color of the cell. For older versions of iOS then this background color would revert to the original background color. For whatever reason that does not happen anymore. Would I simply change the background color of the cell in viewWillAppear or viewDidAppear?
 

Mascots

macrumors 68000
Sep 5, 2009
1,665
1,415
If you are using a UITableViewController and UINavigationController, this behavior is automatic and you shouldn't need to manually deselect the cell when popping the current view off the stack.

For this to happen, you need to ensure viewDidAppear doesn't have any conflicting code and that its super is called. You will also need to make sure you are drawing anything background related in the backgroundView and selectedBackgroundView and not the contentView.

You'll know this is working properly, because if you use the "swipe-back" behavior and hold it, the alpha of selectedBackgroundView will change according to the top view's position.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.