Tuesday, April 21, 2009

iPhone -- Interface Builder, Part 2

See iPhone -- Interface Builder, Part 1 for instructions to get to this point.

So, let's make SecondView use a code file.  Right click on Classes and choose "New File".  On the left of the New File window, under iPhone OS, choose Cocoa Touch Class, and on the right, choose UIVIewController subclass.  Click Next, give it a name of SecondViewController.m and his Finish.  It made the .h for you, automatically.  Build and Run still works, but we really haven't done anything.

Open your SecondView.XIB and change its class to SecondViewController.  It still builds and runs.  Okay...so what have we allowed ourselves to do?  Well, I THINK that we can now override things on the second view, respond to events, set items on it, etc.  So, we have a code file instead of just a dumb view with text on it.

Now, let's get FirstView.xib built.  Right click on "Resources", add new file, choose User Interfaces, and choose View XIB.  A part of me really really really wanted to be able to choose "View Controller XIB" but alas, that is not an option.  Give it a name of FirstView.xib.  Change the File's Owner class to FirstViewController.  Set the File's Owner's "view" outlet to the view that was created.  Add a label to the view so we know it is OUR view, and not the default one they made.  Go back to MainWindow.xib, and set the "Selected First View Control" to load from NIB FirstView.  Finally, delete the View tree under "Selected First View Controller".

Build and run, and you should see YOUR first view already loaded.

Also, go back to MainWindow.xib and change the "Second View Controller"'s class to "SecondViewController".  Not sure if that makes a difference, but I think it does.





No comments:

Post a Comment