Getting reference to view controller of the container view [duplicate]
Asked Answered
S

1

14

I have a viewController which contains a ContainerView(which is setting up a ViewController). I am setting up a segue and in prepareforsegue method I want to get a reference to a viewController which is embedded in the container View. How do I do that. I know that using segue.destinationViewController we can get a reference to UIViewController but I want to also setup the viewController that is being pointed to by the ContainerView.

Stockman answered 7/9, 2013 at 12:17 Comment(0)
M
29

You have your answer already. The container view is a view, not a view controller. It just defines the frame into which the embed segue will put the child view controller's content view.

When the system creates the child VC, it will call your prepareForSegue method, and at that point, segue.destinationViewController will contain the child view controller that is contained in the container view.

Mesolithic answered 7/9, 2013 at 12:36 Comment(4)
when does the call to prepareforSegue happen? is it before the viewdidLoad of the parentViewController or after? I don't know where it gets in the normal lifecycle.Stockman
@Stockman Try putting breakpoints in the methods and you'll see the sequence of calls.Dormie
@Duncan: Thanks a lot for highlighting the concept :) The logic works fineStockman
@Roadblock, prepareForSegue is called after the destination view controller is created, but before it's displayed. View controllers don't create their content views until they are first displayed, so prepareForSegue will be called before viewDidLoad.Mesolithic

© 2022 - 2024 — McMap. All rights reserved.