You asked:
Question number 1 . Where is the code that SegueA will introduce DetailA?
If you call segue A programmatically (for example, call performSegueWithIdentifier ), this code is in the main view controller. Often, however, you do not need to reference it programmatically at all, because when you create a segue in Interface Builder, you often associate it with some control, like a button on the main view, and thus you should not do anything either programmatically to initiate a session. However, when calling segue A, the optional associated shouldPerformSegueWithIdentifier (for iOS 6 and above) and prepareForSegue called in the main view controller.
Question # 2 . In my code for AppDelegate, I need to create an array of all ViewControllers that are in the application. How can I get this array? βIt's in the bulletin board, but how do I programmatically access it.β
I can get the MainViewController by doing the following:
myViewControllerMain = (ViewControllerMain*) self.window.rootViewController;
but I don't know how to access the detail view controllers (a and b)
As a rule, you do not need to support arrays of view controllers (with the possible exception of custom container view controllers, and even then, sometimes you do not need to do this yourself). But, if you need to access some property of your application delegate, you can do something like:
YourAppDelegate *appDelegate = (YourAppDelegate *)[UIApplication sharedApplication].delegate;
Having said that, itβs hard for me to think about situations where it is recommended for the part A controller or part B controller to get a list of view controllers from the host. You really need to explain what kind of business problem you are trying to solve. Typically, you are running some delegate protocol or using some kind of notification process. It depends on the problem you are solving. But you should carefully study your design if A or B needs to get a list of view controllers from the wizard.
Question number 3 . Is DetailA instantiated when the MainViewController is instantiated, or is it created when Seque fires (what is the correct word here - Called?)
With the exception of custom containers and / or embedded segments, the main process:
- segue is triggered;
shouldPerformSegueWithIdentifier optionally called in iOS 6, if NO , then we stop here;- an instance of the destination controller is created; Called
prepareForSegue , which allows you to transfer information from the source controller to the destination controller;- then a view is associated with the destination view controller;
viewDidLoad in the receiver is called (take home message, do not try to manipulate the views / controls in this target view until this point, for example, in the prepareForSegue source);- only then will the representation of the addressee be displayed, its appearance, appearance, etc.
References: