Re: Parent/child view controllers: when shall we use it?
Re: Parent/child view controllers: when shall we use it?
- Subject: Re: Parent/child view controllers: when shall we use it?
- From: Roland King <email@hidden>
- Date: Fri, 01 May 2015 10:37:36 +0800
> On 1 May 2015, at 04:54, Colas B <email@hidden> wrote:
>
> Dear cocoa-dev,
> When building a simple UIViewController, do I have to use addChildViewController: if this VC "owns" other VCs?(By simple VC, I mean I am not creating MyCustomNavigationController or something like that; just a "plain old" VC)
> Imagine for example that I build a view controller (MyCustomVC) and its view has a small subview (fbView) for a Facebook logo and a counter. This "facebook view" is attached to a view controller (FacebookVC) that is called when fbView is touched. So, the FacebookVC definitely needs to be a @property of the MyCustomVC.In this situation, should I really use addChildViewController: and all the mechanism to declare FacebookVC to be a childController of MyCustomVC?
> My belief is that: NO, in this situation it is not to be use. IMHO, MyCustomVC is NOT a container view controller and the usage of child/parent mechanism is only for UINavigationController, TabBar, ... or if I want to create such a "general" class.
> So, am I wrong or am I right ?
> Thanks ;-)Colas
> _____________________________
Had some difficulty completing understanding what you’re trying to do here but I think you’re not right in this instance.
I’ll try putting it another way. If you have a view controller and its view contains subviews which are the views of a different view controller, then you must use the addChildViewController and other methods to make a correct hierarchy of view controllers. Any use of another view controller’s view in your view controller’s view requires that you set up (and tear down) the view controller parent child relationship. if you don’t, rotation won’t work, the view appearance/disappearance methods won’t work and various other methods passed down from view controller to view controller won’t work.
So in your case it seems like your MyCustomVC’s view has, as subview, a fbView which is the ‘view’ of a FacebookVC. Before you add that view to your MyCustomVC’s view’s hierarchy you must make the FacebookVC a child of your MyCustomVC.
TL;DR; If your VC’s view embeds a view from another VC, you must set up a parent-child relationship between the VCs
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden