![]() |
||
[Tutorial] Getting to know Xcode/Interface Buider: PARTS I & II: UITabBar projects
|
||
![]() |
|
|
Thread Tools | Search this Thread |
|
#1
|
|||||||
|
|||||||
|
Alright, it seems that a lot of youse are missing a few steps when it comes to connecting together Xcode and Interface Builder. Hopefully, this will help you see things, and how things work a little better. This tutorial will show you how to create a simple UITabBar based application whose tabs are loaded from separate nib files.
Download Link: http://www.touchrepo.com/SampleCode/CountAppula.zip The first thing you're going to want to do is open a new project. Select a "Tab Based Application" and call it "CountAppula." Be forewarned, when you submit an application to the AppStore, you can't have any spaces in the name. You can change the display name in the Info plist to display "Count Appula" if you feel so inclined. ![]() Now, go in Xcode, click on the resources and delete the SecondView.xib. Double click on MainWindow.xib to open it in Interface Builder. Double click the UITabBarController so it appears on the screen. Click on each of its tabs and delete them. Save the xib and close it. This way, we are starting with a clean slate. ![]() ![]() ![]() Now that we're fresh and clean, go back into Xcode and create two new xibs from the file menu. Let them be empty xibs. Call them "FirstView" and "SecondView" ![]() Double click on "FirstView" to open it up in Interface Builder. In the Inspector, in the "Class Identity" section, set the class as FirstViewController. I should note here that this file was created for us when we created out template. Feel free to override anything you want via code in FirstViewController.h/m. If you want to subclass any view controller for your tab bar app (and it is highly recommended that you do), this is how you would do it. Easy, huh? ![]() Still in the inspector, click on Connections. You'll notice that there is a spot for view. Not everything needs to be connected. View is one of those things that must (or should, to tell you the truth, I've never not connected it) be connected. To set this up, drag a view out of the Library window into the xib's main window. In the inspector, click on the circle next to "view" and drag your mouse over to the view you just created. Once over the view, let go of your mouse button. Congrats, you've just given your view controller a view to control. ![]() ![]() Let's give this view a little color. Double click on the view to open it up. In Inspector's "Attributes" section, change the color. Chose Midnight. Now, Let's save this and close. ![]() Repeat this process for SecondView. Notice that we didn't set up a subclass for this view. That's okay, we can always go back and take care of that. In the interim, when setting a Class Identity, select UIViewController. Also, set this view's color to EggPlant. ![]()
__________________
Last edited by SkylarEC; 01-30-2009 at 01:30 AM.. |
|
#3
|
|||||||
|
|||||||
|
Now, I'll bet that you would like to expand and see how to add a UINavigationController to your UITabBar. That is actually simpler than it might seem.
The first thing we're going to want to do is create a UITableViewController. This is going to be the root view controller for our UINavigationController. In Xcode, click on File and add a new file to your app. Select UITableViewController subclass and name it "Steve." ![]() In Steve.m, scroll down and find the numberOfRowsInSection and cellForRowAtIndexPath methods. In numberOfRows, change the return value to any other positive integer. We'll use 5. In the cellForRow... method, is where we will define the actual cell. Leave this method mostly the same, but add in a switch based on the indexPath.section variable. In its 0 case, we will set the cell's text to a string displaying which numbered cell it is. Case 0 for indexPath.section refers to the first section in your table. [Any additional sections will require more cases, ie case 1: case 2: case 768:, etc. If you want to set up the cell individually, then within an indexPath.section case, add in another switch based upon indexPath.row. Each case refers to each row , exactly the same way the section switch works. ![]() ![]() ![]() ![]() Save this file and reopen MainWindow.xib. |
|
Sponsored Links
|
|
|
|
#4
|
|||||||
|
|||||||
|
In MainWindow.xib, double click on UITabBarController so it displays in its own window. We need to add one more tab. From the Library window, drag a UINavigationController directly onto the tab bar. We will name this tab Steve. Now, click on the navigation bar so that you can edit the Navigation Item attributes. Set the title to "Steve."
![]() ![]() We're nearly done. We need to add a root view controller for our navigation controller. This will be Steve. From the Library window, drag a UITableViewController directly into your UINavigationController. Back in Inspector, set the table view controller's Class Identity as Steve ![]() ![]() Now, you are done! You have a tabbed app with view controllers, a nav controller, and a table view controller. Congrats! Where you go form here is entirely up to you. Hopefully I was able to get you started on the right foot. ![]() Continue on to PART III: http://www.ipodtouchfans.com/forums/...d.php?t=137473 Last edited by SkylarEC; 01-30-2009 at 08:37 PM.. |
|
#5
|
|||||||
|
|||||||
|
There's a spelling error in the thread's title:
[Tutorial] Getting to know Xcode/Interface Builder: UITabBar projects. PARTS I & II |
|
#6
|
|||||||
|
|||||||
|
What ChriB is trying to say is, nice tutorial
. .
|
|
#7
|
||||||
|
||||||
|
Nice Guide! This is off topic, but where'd you get your wallpaper?
|
|
#8
|
|||||||
|
|||||||
|
Yup, I want that wallpaper too
![]() ![]() please please, looks really gr8.
|
![]() |
| Thread Tools | Search this Thread |
|
|