4
votes

If I have a UIViewController called B. If I add UIViewController C as a subview/child view controller of B. Then I add in D as a child view controller of B too. I then remove D from B. In this case should C's viewDidAppear be called afterwards?

The reason I ask is because I am not getting B's call to viewDidAppear. I am planning to do something when B's dismissed.

3
when you remove B, its viewDidDisappear should be calledwaheeda
well that's pretty obvious. I am asking about B's viewDidAppear when C's removed from B as a childadit
'viewDidAppear' will get called when the view is fully loaded (i.e after 'viewWillAppear'). It will not get called when you add/remove a sub view!!Nina
You have viewWillAppear and viewDidAppear. WILL and DID! Its self explanatory. Its even documented on Apple's website and header files...David Skrundz

3 Answers

5
votes

viewDidAppear will not be called when you dismiss a modal view. Think of a modal view as a view on top on the view.

2
votes

What I think, viewDidAppear is not called while adding or removing a subview. The reason behind this is, there are several objects which we add/remove to the view as subview. In this, viewDidAppear will be called again and again which is not a good mechanism. viewDidAppear is called when you load a class object on the current view and move the screen to another class's view and then return to the previous class. In short if you Push a navigationcontroller to a new view and then pop it to the older view then viewDidAppear is Called.

2
votes

As I tested now viewDidAppear is calling when the view come to screen. even 1px. and even if you cover it by any other subView and again discover it this method will NOT call again.

It means it will call only after the subView appear for the first time. unless you remove it and add it again. in your question viewdidAppear of "C" is not calling again after you remove "D".