Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Placeholder objects in Interface Builder

Could someone explain the kinds of placeholder objects that may appear in the Interface Builder document window?

The kinds of placeholders that I know exist are: File's owner, First Responder and App Delegate

Links:

  • This thread explains First Responder.
  • This thread explains the App Delegate.
  • iPhone Interface Builder and Delegates: Answers the question, but not very clearly
like image 983
Casebash Avatar asked Dec 16 '09 02:12

Casebash


2 Answers

I copied this from Apple's developer website on Interface Builder, Hope this helps.

Basically in my own words the placeholders hold everything in your program and they consist of everything that the user sees, like a UIView or a UIImageView, something along those lines

Choose Appropriate Controller Objects

In Cocoa and Cocoa Touch nib files, the File’s Owner placeholder object provides the key link between your application and the objects in the nib file. When you load the nib file, you must provide the nib-loading routine with a pointer to the object that should become the File’s Owner. As part of the loading process, the nib-loading code automatically recreates any connections between the object you specify and the nib file objects that have connections to the File’s Owner.

As you design the architecture of your application, it is important to consider which objects you want to manage your nib files. The presence of only one File’s Owner placeholder object is not without good reason. It is usually best to have a single object coordinate the loading and management of a nib file and its contents. This single point of contact provides the desired barrier between your application’s data model and the visual elements used to present that data model and is at the heart of model-view-controller design.

Beyond the File’s Owner object, you can create additional controller objects directly in your nib file to manage subsets of the nib file. Using multiple controllers in this way lets you compartmentalize the window’s behavior into more manageable chunks. For example, if your window has multiple panes of disparate information, you could create separate controller objects to manage each pane. Each controller would continue to go through the File’s Owner to obtain additional information.

In iPhone applications, it is also possible to include placeholder objects besides File’s Owner in your nib file. These additional placeholder objects are almost always used to represent navigation controllers and other view controllers already in use by your application. The presence of these additional placeholder objects does not diminish the role of File’s Owner though. The File’s Owner object is still responsible for coordinating the overall behavior of the nib file’s contents.

like image 161
Jab Avatar answered Oct 20 '22 23:10

Jab


I think I provided a thorough answer to this here in a response to this question.

Also, I would call the App Delegate a placeholder. A placeholder is an object that's available in a NIB file for making connections to and from, but isn't instantiated when that file is loaded. So, when you have an orange cube in the MainWindow.xib file with the custom class set to "MyAppDelegate", that causes an instance of "MyAppDelegate" to be instantiated when the NIB is loaded. As a counter example, the file's owner of MainWindow.xib is typically "MyApplication", and an instance of MyApplication won't be instantiated when the NIB is loaded, it's already alloced and initted, and is doing the loading. So, the file's owner is a placeholder for an object that already exists, and the app delegate typically isn't.

like image 37
Jon Hess Avatar answered Oct 21 '22 00:10

Jon Hess