views:

88

answers:

2

I have a ViewController that adds to other subviews which have subclassed uiviewControllers

so Its like this:

mainViewController
       |
  v---------v
subVC1   subVC2

And neither subVC1 or subVC2 have the viewDidAppear/viewWillAppear fired on them? The main view controller is creating in the app delegate and it view added there as well to the window.

Here is an xcode project to show my problem: http://www.qfpost.com/download.do?get=92f03538907e72665ea794d98ff8392b

A: 

Firstly, are you sure you actually need to be doing what you're doing with this hierarchy of UIViewControllers? Why can't your MainViewController deal with the views that your subVC1 and subVC2 are responsible for?

Second, your viewWillAppear/viewDidAppear will get called when YOU write the code to call them from your MainViewController. Without knowing anything else about your design it's not really possible to advise on when you should call them, but if the sub-controllers' views are to be always visible when the 'main' view is visible, then it probably makes sense to call them from the viewWillAppear/viewDidAppear methods of your mainViewController.

imaginaryboy
+1  A: 

I had a look at your code. So the problem is that viewWillAppear/viewDidAppear get called when the view is added to the Window, not to one of it's subview. You might want to use viewDidLoad for that.

Julien
Really, I've never had to do this before?
Jonathan
In your example, you add your subVC2's view to your mainViewController's view. That doesn't call viewDidAppear, because this method is called when you add it to you're application's "window" object. Two other mistakes you did in your example : you initialize your subVC2 with the "init" method. I think you want to use the one you built in the nib. You need to use the initWithNibName:bundle: method. Last thing, you might want to release the subVC2 when you added it's subview, because you don't keep any reference to it.
Julien
Oh I didnt mean to use a nib, but I shouldn't release subVC2 because I only passed the subvc2's view to the addsubview method not the whole viewcontroller? Is it also like this about the VW/DA on the iPhone, because I swear this has not happened before to me.
Jonathan