views:

114

answers:

2

I know nib files are serialized objects and they have owner, outlets to make connections. Using XCode Navigation window template I created application, which in its order created 2 nib files - MainWindow and SecondView. I can't understand how MainWindow is referring to SecondView, there is no connection between those two as far as I can see. SecondView's owner is UIViewController and in MainWindow there is a navigation tab which is also UIViewController. But how they are connected in IB I can't understand...

Also I don't understand who is instanciating MainWindow's owner object and where that object is being kept, where is the variable which is UIApplication myApp = [[UIApplication alloc] init].

This one is self-answered: UIApplicationMain and to have the instance variable I need to create outlet somewhere.

If I create 10 nib files with UIViewController owner, who will trigger their deserialization?

If some class is nib file's owner, what is the essential responsibilities of that class? Is it deserializing nib file into memory?

Sorry for unorganized questions, I've been reading numerous articles and docs about nib files, but it is still confusing.

A: 

I am not sure I understand all of your questions correctly. But MainWindown (primary window) nib is loaded when application is loaded. You can verify this from info.plist of your project. you will find the name of primary nib file there. As primary nib is loaded while application is loaded, owner of object is your instance of your application.

Unicorn
Sorry to confusing, I know that it's loading during application startup, but which class is/part of the code is triggering to load it? The only code in the `main` that may load it is `UIApplicationMain` function, so is there a code somewhere say inside of that function which is reading info.plist then deserializing that nib file?
Michael
OK This part is clear for me after re-reading Apple's doc. Loading main nib take place in `UIApplicationMain`. However, I can't get the answer for the first part of my question - how the `SecondView` us linked to `MainWindow`.
Michael
+1  A: 

The MainWindow.xib is loaded when your app launches.

Open up the MainWindow.xib. Make sure you are in List View. You should see an instance of a UINavigationController. Inside that you should see an instance of UIViewController. Select the View Controller instance and take a look at the Inspector Panel. You should see that it has a property "Nib Name" which is set to "RootViewController". So, the viewController will look for and load the "RootViewController" nib at runtime.

So, if you create 10 nibs you are responsible for the deserialization, but Interface Builder has ways to help you keep nibs small and manageable by packaging views in individual nib files.

mustISignUp