0

OK, I'm running into a strange issue which leads me to ask the question - does any code run after viewDidAppear?

Here's some more info. I have a tableViewController (TVC) with custom cells. One of the cells has a button as an accessory. When this TVC loads, the backgroundColor for the button is set. Selecting the cell with the button presents a view controller with a color picker (CPVC). When the CPVC is being dismissed, it first runs a onDismissal block (set in the TVC) for adjusting the color of the button in the TVC. So far the code is working well and the color of the button is set when the color picker view controller is dismissed.

The problem I'm finding is after the button's color gets set, for some reason it resets to the previous color after ~0.25 seconds. You can see the color selected in the color picker set, and then the button's color transitions to its previous color. I don't understand why this is happening. When I inspect local color variables in the debugger, all of them are updated to the new color and it's uncertain where the reference to the previous color still exists. I've plugged in NSLog statements into the TVC's viewDidAppear method and have verified that after the color picker is dismissed, the button's color is set to whatever the user selected by the end of the viewDidAppear method. It's only afterwards the color changes. Just what is running after viewDidAppear?

Wain
  • 118,658
  • 15
  • 128
  • 151
trigonoah
  • 101
  • 8
  • 1
    Possible duplicate of [Looking to understand the iOS UIViewController lifecycle](http://stackoverflow.com/questions/5562938/looking-to-understand-the-ios-uiviewcontroller-lifecycle) – NSNoob Apr 28 '16 at 19:54
  • 1
    Update your question with the code that updates the color of the button in the cell. Also include your `cellForRowAtIndexPath`. Also note that, by default, `UITableViewController` deselects the currently selected row in its `viewDidAppear`. So maybe that deselection is resetting the color. – rmaddy Apr 28 '16 at 20:14

1 Answers1

0

User rmady led me in the right direction. Never knew that UITableViewControllers reset the tableView on viewWillDisappear. According to the documentation:

When the table view is about to appear the first time it’s loaded, the table-view controller reloads the table view’s data. It also clears its selection (with or without animation, depending on the request) every time the table view is displayed. The UITableViewController class implements this in the superclass method viewWillAppear:. You can disable this behavior by changing the value in the clearsSelectionOnViewWillAppear property.

So all I had to do was set the clearsSelectionOnViewWillAppear to NO and everything works as it should. Thanks rmady!

Community
  • 1
  • 1
trigonoah
  • 101
  • 8