views:

105

answers:

2

Do Nib files automatically initialize certain properties? In most objective-c code I've seen, you initialize a pointer with:

MyObject* obj = [MyObject alloc];
[MyObject doStuff];
[obj release];

However, with certain objects (like ViewController Subclasses) UIView objects are used without being initialized, and aren't ever released. Does UIKit automatically look for a .xib file and manage all of the ViewController instances for you?

If so, that is extremely confusing. How does all of this actually work? How can you declare a pointer in a header file, and then magically find it allocated when you need it?

Any help?

(Just a c++ guy complaining about objective-c)

+5  A: 

NIBs are 'frozen' objects, plus the object graph. The objects are instantiated when the NIB is loaded. All links between objects are restored. Also set are pointers in the "Files Owner", the IBOutlets, so the Owner of the NIB has references to the objects just loaded.

Edit: your Info.plist may also refer to a "main" NIB which'll get loaded during app launch. This often contains the main view controllers & views.

Graham Perks
A: 

If you create a viewController and and there is nib file with the same name it will manage The nib. There is also a possibility to call the super constractor with a different nib name. Anyway it is allocated and managed by the viewController

Guy Ephraim