0

I understand that viewWillAppear will be called when duh.... when the the view is about to appear.

But how does IOS know that a controller's view is about to appear?

When exactly that and how it is implemented?

For example, does the childController.view check first that window is one of it's super ancestors? Does the view has a pointer to it's controller? How exactly that works? Does everytime a view is added it check whether it's window is it's super ancestor and whether it is the view outlet of a UIViewController?

For example, if I add childcontroller.view but not to a subview of any view that's being called. Will viewWillAppear called?

Does the childController need to be the a child of a parentController so that viewWillAppear of the childController will be called when the parentController's viewWillAppear is called automatically?

Anonymous White
  • 2,149
  • 3
  • 20
  • 27

1 Answers1

2

The view is loaded by your controller using the - (void)loadView method. This method is implemented to load a blank view or a view from a nib/storyboard. You only need to override it if you really need to create a view hierarchy from scratch.

All of the magic happens when the value of the view property is first requested and the controller detects the value is nil. All of the life cycle method calls are handled by the UIViewController. There is nothing you need to do other than implement the methods if you need them. Remember one thing: There is no guarantee the view has been loaded until the - (void)viewDidLoad method has been called.

Everything I've learned about controllers how they work has come from the View Controller Programming Guide.

Bradley M Handy
  • 603
  • 6
  • 15
  • Good enough. +1. So, when a view is nil and we access it, the controller call loadView. Let me think for a while. What about if view is not nil. How do controllers know that the view is disappearing? What about if you remove the view from it's superview. How do controllers got notified? – Anonymous White Oct 25 '12 at 02:48
  • That's what I want to understand. Does the UIView has a weak pointer to it's controller? If not, how the hell the UIViewController knows that it's view has been added. – Anonymous White Oct 26 '12 at 05:59
  • If you want further information related to this, you should ask this on an Apple forum. You can also explore the header files to see what nifty nuggets of information are there. I remember there being a reference to a UIViewController in the UIView.h file; so I'm presuming the UIView has a reference to its controller. Other than that, I'm at my limit of knowledge on this subject. – Bradley M Handy Oct 26 '12 at 14:20
  • Not a very good answer, but yours are the only answer. I'll select this when no other answer coming. – Anonymous White Oct 27 '12 at 14:02