Subscribe to our RSS news feed
AAPL 275.62 (0.56)

iPhone SDK - Interface Builder Tutorial
*****
  • Group: Members
  • Posts: 350
  • Joined: 28-February 08
  • From: Russia
  • Member No.: 193,193
This is just a quick jump-start to using Interface Builder with Cocoa Touch apps and Xcode. Since the documentation offers no explanation of how to do this, I thought this may be helpful.
  1. Create a new Cocoa Touch project in Xcode.
  2. You should be presented with the main window, you can ignore this for now. Open Interface Builder. The New Document window will open, select Window in the fourth tab.
  3. Now just add whatever you want from the library to your view. Save the view to the directory of your recently created Xcode project as "MainWindow", and it should ask if you if you wish to add it to the project. Check the box next to the app name you just created, and hit Add.
  4. Go back to Xcode, and open up <your_app_name>appDelegate.m. It should look like:
    CODE
    #import "SDK_IB_TestAppDelegate.h"
    #import "MyView.h"

    @implementation SDK_IB_TestAppDelegate

    @synthesize window;
    @synthesize contentView;

    - (void)applicationDidFinishLaunching:(UIApplication *)application {    
        // Create window
        self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
        
        // Set up content view
        self.contentView = [[[MyView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]] autorelease];
        [window addSubview:contentView];
        
        // Show window
        [window makeKeyAndVisible];
    }

    - (void)dealloc {
        [contentView release];
        [window release];
        [super dealloc];
    }

    @end

  5. We need to remove all the extra view code, and load our XIB. Edit the applicationDidFinishLaunching: method to look like this:
    CODE
    - (void)applicationDidFinishLaunching:(UIApplication *)application {    
        // Create window
        self.window = [[[NSBundle mainBundle] loadNibNamed:@"MainWindow" owner:self options:nil] objectAtIndex:0];
        
        // Show window
        [window makeKeyAndVisible];
    }

  6. Build and Go. Your new iPhone App should be using the XIB you just made.

Hope this gets people started with Interface Builder.
PM Profile Card
Go to the top of the page
+ Quote Post

Posts in this topic
- stroke   iPhone SDK - Interface Builder Tutorial   Mar 27 2008, 11:03 PM
- - MasterofComputers   QUOTE (stroke @ Mar 27 2008, 07:03 PM) Th...   Mar 27 2008, 11:39 PM
- - C.J.   Not too difficult. Just takes little away from the...   Mar 28 2008, 04:54 AM
- - mmk   I'm trying a simple example - I just put up a ...   Mar 28 2008, 08:41 AM
- - geez   Brilliant little jump-start tutorial - one for the...   Mar 28 2008, 11:56 AM
- - DaveGee   QUOTE (stroke @ Mar 27 2008, 07:03 PM) Th...   Mar 28 2008, 01:41 PM
- - pix   cool thanks! any idea how to use UINavigation...   Mar 28 2008, 03:08 PM
- - maverick808   I have the same problem in that it crashes when I ...   Mar 28 2008, 06:10 PM
- - stroke   For those with the crashing problem, have you chec...   Mar 28 2008, 07:04 PM
- - maverick808   It's not the way the text is set that is the p...   Mar 28 2008, 07:29 PM
- - stroke   Ah, yes, I see what you mean… perhaps it is ...   Mar 28 2008, 08:25 PM
|- - maverick808   QUOTE (stroke @ Mar 28 2008, 09:25 PM) Ah...   Mar 28 2008, 08:33 PM
- - mmk   OK I have made it work guys .. The problem was th...   Mar 29 2008, 05:06 AM
|- - maverick808   QUOTE (mmk @ Mar 29 2008, 06:06 AM) I hav...   Mar 29 2008, 01:13 PM
|- - DaveGee   QUOTE (maverick808 @ Mar 29 2008, 09:13 A...   Mar 29 2008, 01:31 PM
- - mmk   Here is the first HelloWorld working example (with...   Mar 29 2008, 07:17 AM
|- - pix   the button example is helpful, thanks, but do you ...   Mar 29 2008, 11:27 AM
|- - DaveGee   QUOTE (mmk @ Mar 29 2008, 03:17 AM) Here ...   Mar 29 2008, 12:59 PM
|- - alpineedge3   QUOTE (mmk @ Mar 29 2008, 03:17 AM) Here ...   Mar 30 2008, 08:20 PM
|- - mmk   QUOTE (alpineedge3 @ Mar 31 2008, 04:20 A...   Mar 30 2008, 11:18 PM
|- - alpineedge3   QUOTE (mmk @ Mar 30 2008, 07:18 PM) In IB...   Mar 31 2008, 02:08 AM
|- - DaveGee   Attached is a screenshot of the controls I was ask...   Mar 31 2008, 02:31 AM
|- - Ian Davies   QUOTE (DaveGee @ Mar 31 2008, 03:31 AM) A...   Mar 31 2008, 10:07 PM
|- - DaveGee   QUOTE (Ian Davies @ Mar 31 2008, 06:07 PM...   Mar 31 2008, 11:22 PM
- - newky2k   Interface Builder allows you to create the xib fil...   Mar 29 2008, 07:36 PM
- - stroke   You shouldn't use lastObject as the the last o...   Mar 29 2008, 10:53 PM
- - munky   - removed pointless flamewar -   Mar 30 2008, 12:29 AM
- - mmk   Here is a semi-working example with controllers. Y...   Mar 30 2008, 02:30 PM
- - DaveGee   Okay has anyone tried table views AND turning on U...   Mar 30 2008, 10:01 PM
- - grabberslasher   It's more proper to just use the line [[NSBu...   Mar 30 2008, 10:09 PM
- - mp05   Hey , are NSLog statements getting printed in the ...   Mar 31 2008, 06:10 PM
- - JoLePaBo   Hello, This is my first post (I am sorry, but I a...   Mar 31 2008, 06:32 PM
- - stroke   mp05, I have the same problem. JoLePaBo, if you ar...   Mar 31 2008, 07:10 PM
- - Mark Snow   Hi all, I discovered it is actually possible to l...   Mar 31 2008, 10:00 PM
- - stroke   Make sure to set the tableview's delegate to s...   Mar 31 2008, 11:36 PM
|- - alpineedge3   QUOTE (stroke @ Mar 31 2008, 07:36 PM) NS...   Mar 31 2008, 11:47 PM
|- - DaveGee   QUOTE (stroke @ Mar 31 2008, 07:36 PM) Ma...   Mar 31 2008, 11:59 PM
- - stroke   Yeah, you're right, it still outputs to the sy...   Apr 1 2008, 12:05 AM
|- - DaveGee   QUOTE (stroke @ Mar 31 2008, 08:05 PM) Ye...   Apr 1 2008, 12:12 AM
- - mp05   i have a text-field (its an IBOutlet of UITextFiel...   Apr 1 2008, 12:40 AM
|- - DaveGee   QUOTE (mp05 @ Mar 31 2008, 08:40 PM) i ha...   Apr 1 2008, 12:52 AM
- - stroke   mp05, do something like: CODENSString *string = ...   Apr 1 2008, 01:02 AM
|- - PascalW   QUOTE (stroke @ Apr 1 2008, 03:02 AM) mp0...   Apr 1 2008, 07:11 AM
|- - DaveGee   QUOTE (PascalW @ Apr 1 2008, 03:11 AM) Ju...   Apr 1 2008, 11:10 AM
|- - DaveGee   Okay... Still researching that issue I'm havi...   Apr 1 2008, 01:08 PM
- - mp05   No DaveGee. I have tried it already, its not worki...   Apr 1 2008, 01:03 AM
- - mmk   Anyone made a UITableView in IB working? In my exa...   Apr 1 2008, 03:03 AM
- - stroke   Try doing [tableView reloadData];   Apr 1 2008, 03:20 AM
|- - mmk   QUOTE (stroke @ Apr 1 2008, 11:20 AM) Try...   Apr 2 2008, 12:47 AM
- - mp05   Thanks a lot pascal... finally it worked with the ...   Apr 1 2008, 08:11 AM
- - stroke   PascalW, that works, but only if the only thing in...   Apr 1 2008, 08:00 PM
|- - PascalW   QUOTE (stroke @ Apr 1 2008, 10:00 PM) Pas...   Apr 1 2008, 08:46 PM
|- - DaveGee   QUOTE (stroke @ Apr 1 2008, 04:00 PM) Dav...   Apr 2 2008, 01:35 PM
|- - mmk   QUOTE (DaveGee @ Apr 2 2008, 09:35 PM) Co...   Apr 2 2008, 05:09 PM
||- - DaveGee   QUOTE (mmk @ Apr 2 2008, 01:09 PM) By the...   Apr 2 2008, 05:39 PM
||- - turinreza   When I do the sample, for MainWindow, all that i s...   Apr 3 2008, 12:41 AM
|- - Greg R   QUOTE (DaveGee @ Apr 2 2008, 01:35 PM) Co...   Apr 2 2008, 05:30 PM
- - mp05   Any able to change the attibutes of a button or te...   Apr 1 2008, 09:53 PM
- - scottjg   I don't want to say that instantiating the gui...   Apr 2 2008, 12:23 AM
- - exd   In order to have XCode & IB working together, ...   Apr 3 2008, 09:29 AM
|- - turinreza   QUOTE (exd @ Apr 3 2008, 01:29 AM) In ord...   Apr 3 2008, 06:20 PM
- - javid.alimohideen   Hi, Has anyone tried to figure out how to use the ...   Apr 3 2008, 03:18 PM
- - mdesaro   Does anyone have a simple walkthrough/explanation ...   Apr 3 2008, 09:46 PM
- - mp05   Any idea how to draw a level indicator(bar)on a wi...   Apr 4 2008, 08:13 AM
- - martinnw   Hmm... What am I doing wrong? I'm trying to f...   Apr 4 2008, 11:17 AM
|- - javid.alimohideen   QUOTE (martinnw @ Apr 4 2008, 11:17 AM) H...   Apr 4 2008, 02:07 PM
- - dj512   Thanks for these examples. I've gone through b...   Apr 4 2008, 03:35 PM
- - mp05   From the second Beta version,NSLog got messed up. ...   Apr 4 2008, 06:06 PM
- - drennyn   May be off topic, but has anyone had any luck sign...   Apr 5 2008, 03:13 AM
|- - mmk   QUOTE (drennyn @ Apr 5 2008, 11:13 AM) Oh...   Apr 5 2008, 06:48 AM
|- - alpineedge3   QUOTE (mmk @ Apr 5 2008, 02:48 AM) Haven...   Apr 8 2008, 04:21 AM
|- - javid.alimohideen   QUOTE (alpineedge3 @ Apr 8 2008, 04:21 AM...   Apr 8 2008, 02:22 PM
|- - alpineedge3   QUOTE (javid.alimohideen @ Apr 8 2008, 10...   Apr 9 2008, 03:02 AM
|- - javid.alimohideen   QUOTE (alpineedge3 @ Apr 9 2008, 03:02 AM...   Apr 9 2008, 02:01 PM
|- - alpineedge3   QUOTE (javid.alimohideen @ Apr 9 2008, 10...   Apr 11 2008, 04:05 AM
|- - javid.alimohideen   QUOTE (alpineedge3 @ Apr 11 2008, 04:05 A...   Apr 14 2008, 05:11 PM
- - uprise78   I've got 2 questions for anyone out there with...   Apr 5 2008, 09:15 PM
|- - mmk   QUOTE (uprise78 @ Apr 6 2008, 05:15 AM) 2...   Apr 6 2008, 12:40 AM
- - uprise78   So, I used IB to wire up two view controllers (nam...   Apr 6 2008, 03:40 AM
- - mdesaro   javid, that worked like a charm. Thanks. I tried...   Apr 8 2008, 03:41 PM
|- - javid.alimohideen   QUOTE (mdesaro @ Apr 8 2008, 03:41 PM) ja...   Apr 8 2008, 03:45 PM
- - mdesaro   javid, I've got a semi-solution/hack that is ...   Apr 8 2008, 09:12 PM
|- - javid.alimohideen   QUOTE (mdesaro @ Apr 8 2008, 09:12 PM) ja...   Apr 9 2008, 04:40 PM
- - mp05   Home button on the navigation bar: hi, can anyone...   Apr 10 2008, 06:36 PM
|- - javid.alimohideen   QUOTE (mp05 @ Apr 10 2008, 06:36 PM) Home...   Apr 10 2008, 07:07 PM
|- - mp05   QUOTE (javid.alimohideen @ Apr 10 2008, 07...   Apr 10 2008, 10:44 PM
- - stroke   He means to implement the following method in your...   Apr 11 2008, 12:30 AM
- - mp05   thanks stroke.. got it... Has anyone tried of get...   Apr 11 2008, 06:34 PM
- - mp05   thanks stroke.. got it... Has anyone tried of get...   Apr 11 2008, 06:34 PM
- - mdesaro   mp05, it's pretty simple using remote servers....   Apr 11 2008, 09:50 PM
- - rbenjamin   I'm having the exact same problem as alpinee -...   Apr 13 2008, 05:02 AM
- - mp05   Can anyone pls advice me on the following. I have ...   Apr 14 2008, 08:08 PM
|- - mdesaro   mp05, You're in the wrong place asking about ...   Apr 14 2008, 08:33 PM
- - rbenjamin   I'm trying to get a basic table view working w...   Apr 16 2008, 05:11 AM
|- - javid.alimohideen   QUOTE (rbenjamin @ Apr 16 2008, 05:11 AM)...   Apr 16 2008, 05:20 AM
- - rbenjamin   I'm trying to create tables in code, and I...   Apr 16 2008, 08:39 PM
- - stroke   If you're programmatically allocating it, put ...   Apr 16 2008, 08:42 PM
|- - Mark Snow   QUOTE (stroke @ Apr 16 2008, 08:42 PM) If...   Apr 17 2008, 11:43 AM
- - rbenjamin   QUOTE If you're programmatically allocating it...   Apr 16 2008, 08:53 PM
- - rbenjamin   Ok, so my table displays now, I just can't int...   Apr 17 2008, 03:53 PM
2 Pages V   1 2 >

Reply to this topic Start new topic

1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 

RSS Lo-Fi Version Time is now: 31st July 2010 - 01:53 PM