background preloader

Learning outlets...

Facebook Twitter

Cocoa: What is "File's Owner" in a nib? One of the things I had most trouble with while writing my first Cocoa application was understanding what a File's Owner in a nib file was and what role it fulfilled.

Cocoa: What is "File's Owner" in a nib?

Apple's documentation seems to imply that understanding File's Owner is important (it is) but doesn't really do a good job of explaining the concept. And I'm not alone - this email thread contains a pretty good summary of what Apple's documentation says and the confusion it might create. That same thread has several peoples' attempts to explain what it is. I really didn't get too much from those explanations and ended up explaining it to myself by piecing together data from a few experiments.

Now that I think I understand what it's for, I figured I should try and put my take out there as well in case it ends up helping someone else in the future. The File's Owner of your primary nib file is, by default, the NSApplication class and this comes ready-made for you when you create your Cocoa application. Cocoa - What describes the "File's Owner" best in objective-c / coca Nib. Objective c - IBOutlet confusion. iPhone Programming Tutorial - Connecting Code to An Interface. Finally, we get to write some real code! In this tutorial, I will show you how to create an interface using Interface Builder and connect it to your code.

We will be creating a and a Now, don’t be intimidated that this tutorial is so long. I have really went into detail explaining everything as I go. You could easily scan over it and get the gist of it. Here’s how the application will work: The user will tap inside a text box which brings up the iPhone’s keyboard The user will type their name using the keyboard The user will press a button The label will update with a greeting containing that user’s name (ex.

If the user fails to enter in text, the label will say something like “Please Enter Your Name” This tutorial assumes that you have completed the following tutorials Hello World Tutorial Using UITableView. Why would you use Interface Builder for iPhone Development? I don’t understand why you’d use Interface Builder to create a UI for an iPhone application.

Why would you use Interface Builder for iPhone Development?

When I started building my first iPhone application at Shine, my colleagues advised me to avoid using Interface Builder. They’d tried using it when they were first starting out, but found that it just got in the way and made the learning curve steeper than it needed to be. The problem for me was that many of the available books and tutorials for iPhone development used Interface Builder.

Many of the sample apps on Apple’s site use it as well. I was having trouble figuring out how to not use it, so I took a deep breath and gave it a go. I got confused pretty quickly. Sure, I probably would have figured it out, but why make life harder than it needs to be? My Theory Perhaps all the iPhone books and tutorials have been written by people who already had experience developing with Interface Builder and Nibs for Mac OS X.

Don't Fear the Interface Builder. The question of whether to use Interface Builder is not one most experienced Cocoa developers that I've talked to struggle with.

Don't Fear the Interface Builder

Basically, they use Interface Builder unless they have a good reason not to. And reasons not to are relatively rare. In the days before the iPhone, Apple's Cocoa Dev Mailing List would once in a while get a question from somebody new to Objective-C and Cocoa who wanted to create their GUIs programmatically. Here's a response to one of those questions from knowledgeable Cocoa/NeXTSTEP programmer and frequent Cocoa-Dev contributor John C. Randolph way back in 2001 that pretty much nails it: This question comes up fairly often, and the answer is yes, it can all be done in code (which, after all is what -loadNibFile: is doing), but there's no more reason to abandon IB than there is to forego compilers and write all your code with a hex editor.

Yep. If your gut is telling you to avoid Interface Buidler, for whatever reason, your gut is wrong. Simple, but elegant. iPhone Programming Fundamentals - Outlets and Actions. An understanding of outlets and actions is one of the first things you will need for iPhone programming.

iPhone Programming Fundamentals - Outlets and Actions

For someone coming from the .NET background, this is a concept that requires some time to get used to - the concepts are similar, but it is a different way of doing things. And so, in this article, I am going to show you what outlets and actions are. At the end of this article, you will have a solid understanding of how to create outlets and actions, and be on your way to creating great iPhone apps. First, the basics So let's start by creating a really simple project to see how everything fits together. Figure 1 Creating a View-based Application project The View-based Application project template provides the quickest way to start writing an iPhone application. Figure 2 Examining the content of a View-based application project in Xcode In short, when the application is loaded, the main window loads the view represented by the OutletsAndActionsViewController.xib file.