Viewdidload and viewwillappear


#1

So I’m a little confused about the very last bits of code in BNRColorViewController that implement hiding the rightBarButtonItem and setting the slider values for pre-existing colors.

  1. if we are setting the rightBarButtonItem to nil, how does it get recreated the next time the view is displayed ? I thought views were loaded once from nib then cached as long as possible, are they recreated from the nib/storyboard every time they are displayed ?

  2. Why is the button hiding code in viewWillAppear: and the slider setup code in viewDidLoad: ? Same question, I thought it was mentioned early in the book that any one time initialization should go in viewDidLoad: which is called after a nib is loaded, and any code that needs to run every time a view is displayed should go in viewWillAppear: which I believe is more of an appropriate spot for the setting of the slider values which should happen every time the view is shown.


#2

Going to try answering my own question…

It seems, from the digging around online that I’ve done, that when a view controller is presented modally, that viewDidLoad and viewWillAppear are called back to back every time the view controller is presented. So that is why this works.

However, this code would not show the sliders correctly if you decided to move that view controller to, lets say, a tab bar controller where viewDidLoad gets called only once.

I welcome any further comments to validate or negate my conclusion.