views:

729

answers:

2

Hey folks,

I'm starting to go a little crazy with this one.

I have an iphone application with a somewhat complex view structure it is a tabbed application with either a view controller or a navigation controller on each tab.

The main controller for one tab uses the viewDidAppear callback to reload any data that has been modified since the last time it was displayed and this behaves fine in most cases. The issue I have run into is that when I navigate in subviews(within the same tab) using the standard navigation controller push/pop mechanism the viewWillAppear and viewDidAppear on the main view always fire when I navigate back to it. However if I load a modal view controller and then dismiss it, the viewWillAppear continues to fire but the viewDidAppear stops firing.

I am almost certain that this is tied to the need to manually call these callbacks on the modal controller but I cannot find the reference info on how to do this correctly. (I only see this viewDidAppear bug on the hardware, in the simulator it works as I'd expect)

If you need further clarification let me know and thanks for any input.

+1  A: 

Yes, this is how it works. You are better off switching to using viewWillAppear.

This has the added advantage of updating the data before the screen is redrawn.

corydoras
I was actually using viewWillAppear for all of these types of operations for quite a while but had changed it to use viewDidAppear because the responsiveness of the UI is improved substantially by updating the data after the view is reloaded vs before.
paulthenerd
That is interesting! In my apps so far, they have felt more responsive to use viewWillAppear, using viewDidAppear made my apps feel slow because the tables were filled only after the view finished sliding in. (ie it made it appear that the tables took a while to load)
corydoras
A: 

viewDidLoad should be used for one-time setup operations:

  • Setting titles
  • Instantiating subviews, content arrays
  • Anything else related to the infrastructure of the view in question

After that, use viewWillAppear: to do anything related to refreshing data. You shouldn't have to call any of the viewDid/viewWill methods manually – that's handled by the innards of UIView. viewDidLoad won't fire after you dismiss a modal view controller because, more than likely, the view never unloaded. viewDidLoad fires fine when you're navigating the a view controller stack since the new views need memory, requiring other views to unload, then be reloaded when they reappear.

Danilo Campos