user434565
user434565

Reputation: 909

What is with Objective C Nib Files?

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)

Upvotes: 2

Views: 4668

Answers (2)

Guy Ephraim
Guy Ephraim

Reputation: 3520

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

Upvotes: 0

Graham Perks
Graham Perks

Reputation: 23400

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.

Upvotes: 7

Related Questions