Jump to content

iPhone SDK - Interface Builder Tutorial


115 posts in this topic

Recommended Posts

javid, that worked like a charm. Thanks. I tried using the same logic to get navbars working but, unfortunately I cant seem to figure out how to wire up a view controller in IB (equivalent to the initWithRootController method).

 

Has anyone had any luck getting nav bars up and running through IB?

Link to comment
Share on other sites

javid, that worked like a charm. Thanks. I tried using the same logic to get navbars working but, unfortunately I cant seem to figure out how to wire up a view controller in IB (equivalent to the initWithRootController method).

 

Has anyone had any luck getting nav bars up and running through IB?

Same here. I have tried several differeny ways to wire up Navigation Controller using IB, and no luck. If someone has figured it out, please post. For now, I can just think that it is a bug in IB.

 

Javid

Link to comment
Share on other sites

javid,

 

I've got a semi-solution/hack that is almost there. Do the following:

 

1. Add a UINavigationController in IB

2. Add 2 UIViewControllers each with 1 UINavigationItem. Be sure to set titles for your UIViewControllers

3. Add an outlet to your UINavigationController called myRootViewController

4. Connect the outlet to one of the UIViewControllers you just make

5. Add an outlet to the UIViewController you just linked to your UINavigationController called childViewController

6. Connect the outlet to the second UIViewController

7. Write out class files for the UINavigationController and the first UIViewController

8. After unmucking the class files that IB makes add to the UINavigationController a - (void)awakeFromNib method with the following line:

[self initWithRootViewController:myRootViewController];

9. To display your nav controller call [window addSubview:navViewController.view]; from your main AppDelegate

10.To load a second view into the nav controller with the fancy slide effect add a button to the first UIViewController with the following line:

[[self navigationController] pushViewController:childViewController animated:YES];

 

So, it's not quite 100% IB but it is as close as I can get so far. Anyone with additions/comments/fixes please post

Link to comment
Share on other sites

Ok. Here is a simple walkthrough on getting the tabbars working.

...

 [window addSubView: tabBarController.view];
  [window makeKeyAndVisible];

...

 

thanks for the guide. i'm still having a problem though. The app builds ok but with 1 warning regarding your addSubView method, and i don't see the tabbar:

[window addSubView: tabBarController.view];

warning: 'UIWindow' may not respond to '-addSubView:'

(Messages without a matching method signature will be assumed to return 'id' and accept '...' as arguments)

 

my AppDelegate looks like this:

#import <UIKit/UIKit.h>

@interface AppDelegate : NSObject {

IBOutlet UIWindow *window;

IBOutlet UITabBarController *tabBarController;

}

@end

 

any suggestions? thanks.

Link to comment
Share on other sites

thanks for the guide. i'm still having a problem though. The app builds ok but with 1 warning regarding your addSubView method, and i don't see the tabbar:

 

 

my AppDelegate looks like this:

 

 

any suggestions? thanks.

Its a lowercase 'v'

[window addSubview: tabBarController.view];

Link to comment
Share on other sites

javid,

 

I've got a semi-solution/hack that is almost there. Do the following:

 

1. Add a UINavigationController in IB

2. Add 2 UIViewControllers each with 1 UINavigationItem. Be sure to set titles for your UIViewControllers

3. Add an outlet to your UINavigationController called myRootViewController

4. Connect the outlet to one of the UIViewControllers you just make

5. Add an outlet to the UIViewController you just linked to your UINavigationController called childViewController

6. Connect the outlet to the second UIViewController

7. Write out class files for the UINavigationController and the first UIViewController

8. After unmucking the class files that IB makes add to the UINavigationController a - (void)awakeFromNib method with the following line:

[self initWithRootViewController:myRootViewController];

9. To display your nav controller call [window addSubview:navViewController.view]; from your main AppDelegate

10.To load a second view into the nav controller with the fancy slide effect add a button to the first UIViewController with the following line:

[[self navigationController] pushViewController:childViewController animated:YES];

 

So, it's not quite 100% IB but it is as close as I can get so far. Anyone with additions/comments/fixes please post

Thanks that really helped. In my app, I am trying to combine both TabBarCOntroller and Nav Bar Controller and i get insert 'nil' exception.

Let me explain what i am trying to do:

1. Create a TabBar Controller

2. Create two ViewControllers and One Nagivation COntroller,

3. In my TabBar Cotroller, i drag the multi-outlet views to the first ViewController and Navigation Controller.

 

All I am tryng to achieve, have two tabs, one tab will have view with navigation items and the other one is just a simple view controller

 

Has anyone tried to use both TabBarCOntroller and NavigationCOntroller in IB?

If so, please post your thoughts

Link to comment
Share on other sites

Home button on the navigation bar:

 

hi, can anyone pls guide me which class/method i need to use in the following.

 

i will have a home button on the navigation bar , pressing the button should lead me to the home page of the iPhone where all the applications will be listed. (Like the black button on the iPhone simulator / iPhone ,outside the screen).

Link to comment
Share on other sites

Home button on the navigation bar:hi, can anyone pls guide me which class/method i need to use in the following.i will have a home button on the navigation bar , pressing the button should lead me to the home page of the iPhone where all the applications will be listed. (Like the black button on the iPhone simulator / iPhone ,outside the screen).
My wild guess would be to quit the application, so it automatically takes you to Home Screen. I don't have access to code, but something like below on the touc up inside action of button:
[exit(0)];

My wild guess would be to quit the application, so it automatically takes you to Home Screen. I don't have access to code, but something like below on the touc up inside action of button:
[exit(0)];

BTW, beware iPhone apps will not run in background. So, if you are doing some cleanups or saving preferences, its better to do it in the UIApplicationDelegate class, applicationWillTerminate method.Hope, this info helps.
Link to comment
Share on other sites

My wild guess would be to quit the application, so it automatically takes you to Home Screen. I don't have access to code, but something like below on the touc up inside action of button:
[exit(0)];

BTW, beware iPhone apps will not run in background. So, if you are doing some cleanups or saving preferences, its better to do it in the UIApplicationDelegate class, applicationWillTerminate method.Hope, this info helps.

 

Thanks a lot Javid...It worked out fine...Could you please explain bit more on the second part of your reply (abt UIApplicationDelegate class, applicationWillTerminate method ). I have this Home Method (method which will quit the application) in one of my UIViewController. pls guide me with your info.

Link to comment
Share on other sites

Its a lowercase 'v'

[window addSubview: tabBarController.view];

 

ok i corrected that, but the tab bar still doesn't appear, it seems like the same problem as RossOliver's in the apple discussion http://discussions.apple.com/thread.jspa?messageID=7012574

 

i've been wrestling with this for a day and a half...can someone look at the attached project to see what's wrong? i'm using the beta 3 sdk. thanks in advance.

onetab.zip

Link to comment
Share on other sites

I'm having the exact same problem as alpinee - When I follow the tutorial (on page 4 for making the tab bar in IB) and launch the interface it just crashes. I have played with it for 4 hours without moving, and can't get it to launch. Hope there's something I'm missing.

Link to comment
Share on other sites

ok i corrected that, but the tab bar still doesn't appear, it seems like the same problem as RossOliver's in the apple discussion http://discussions.apple.com/thread.jspa?messageID=7012574

 

i've been wrestling with this for a day and a half...can someone look at the attached project to see what's wrong? i'm using the beta 3 sdk. thanks in advance.

 

Alpinee,

I dont have access to mac right now, to test your project. But, make sure you have the view controller linked up to the Multi-outlet "viewControllers" of the TabBar Controller in IB.

 

Javid

Link to comment
Share on other sites

Can anyone pls advice me on the following. I have involved in Mac OS cocoa applications. i want some help w.r.t Cocoa Touch applications. i am also new to the networking area...

 

On my View, i have the following fields,

TextField1 - user will give a input (say user gives employee #)

TextField2 - Field to show the output. Read only field. ( say employee Name will be dispalyed)

UI Button - On clicking this button, depending on the employee # in the TextField1, corresponding employee name will be displayed in the TextField2.

 

the employee data is in the oracle database sitting on the remote machines ( say an unix machine). I ultimate aim is build a three tire architecture application(Cocoa Touch Client - Application server - Database). can anyone have any idea how to handle the transactions. any classes/methods that i can refer. any pointers will he really helpful.

Link to comment
Share on other sites

mp05, You're in the wrong place asking about this. What you are asking is a HUGE task that spans many, many books. You need to break down your project into steps and learn each one separately.

 

Google is your friend.

 

http://www.google.com/search?hl=en&btn...Oracle+tutorial

http://www.google.com/search?hl=en&btn...server+tutorial

http://www.google.com/search?hl=en&btn...=cocoa+tutorial

 

Good luck

 

Can anyone pls advice me on the following. I have involved in Mac OS cocoa applications. i want some help w.r.t Cocoa Touch applications. i am also new to the networking area...

 

On my View, i have the following fields,

TextField1 - user will give a input (say user gives employee #)

TextField2 - Field to show the output. Read only field. ( say employee Name will be dispalyed)

UI Button - On clicking this button, depending on the employee # in the TextField1, corresponding employee name will be displayed in the TextField2.

 

the employee data is in the oracle database sitting on the remote machines ( say an unix machine). I ultimate aim is build a three tire architecture application(Cocoa Touch Client - Application server - Database). can anyone have any idea how to handle the transactions. any classes/methods that i can refer. any pointers will he really helpful.

Link to comment
Share on other sites

I'm trying to get a basic table view working with interface builder and keep getting the error

 

...MainWindow.nib /Users/ben/Documents/Projects/ZappFlower/MainWindow.xib

/* com.apple.ibtool.errors */

Internal Error:

Description: ibtool failed with exception: [NOTE: this exception originated in the server.]

The delegate must be set for <UITableView: 0x372b10>, but is currently nil.

The delegate must be set for <UITableView: 0x372b10>, but is currently nil.

The delegate must be set for <UITableView: 0x372b10>, but is currently nil.

The delegate must be set for <UITableView: 0x372b10>, but is currently nil.

The delegate must be set for <UITableView: 0x372b10>, but is currently nil.

The delegate must be set for <UITableView: 0x372b10>, but is currently nil.

 

EVEN THOUGH I am almost certain i've set things correctly, I create an IBOutlet for the table view, and I set the delegate and datasource to self - I thought that was all I should have to do. Why would it keep saying it's nil?

Link to comment
Share on other sites

I'm trying to get a basic table view working with interface builder and keep getting the error

 

...MainWindow.nib /Users/ben/Documents/Projects/ZappFlower/MainWindow.xib

/* com.apple.ibtool.errors */

Internal Error:

Description: ibtool failed with exception: [NOTE: this exception originated in the server.]

The delegate must be set for <UITableView: 0x372b10>, but is currently nil.

The delegate must be set for <UITableView: 0x372b10>, but is currently nil.

The delegate must be set for <UITableView: 0x372b10>, but is currently nil.

The delegate must be set for <UITableView: 0x372b10>, but is currently nil.

The delegate must be set for <UITableView: 0x372b10>, but is currently nil.

The delegate must be set for <UITableView: 0x372b10>, but is currently nil.

 

EVEN THOUGH I am almost certain i've set things correctly, I create an IBOutlet for the table view, and I set the delegate and datasource to self - I thought that was all I should have to do. Why would it keep saying it's nil?

I have the same issue. I believe it's a bug in SDK beta3. For now, create your table views in code.

Link to comment
Share on other sites

I'm trying to create tables in code, and I'm trying to do it with - (void)awakeFromNib. I am using code from apple's site,

 

UITableView *tableView = [[uITableView alloc] initWithFrame:[[uIScreen mainScreen] applicationFrame]

style:UITableViewStylePlain];

 

tableView.delegate = self;

tableView.dataSource = self;

tableView.rowHeight = 54;

[tableView reloadData];

 

But I just can't get it to display. I'm also adding the *tableview as a sub view, with no luck. Anyone have any ideas? Like I said, I am trying to use the awakefromnib because I am using a nib files for almost all of my views, with a few extras added through that method.

Link to comment
Share on other sites

If you're programmatically allocating it, put it in the - (void)applicationDidFinishLaunching:(UIApplication *)application method.

 

 

This just crashes my application.

 

EDIT: Can you give me an example? Maybe I'm not following you ?

Link to comment
Share on other sites

If you're programmatically allocating it, put it in the - (void)applicationDidFinishLaunching:(UIApplication *)application method.

 

When using XIB objects , this works but I don't understand why. In Cocoa applicationDidFinishLaunching: was called BEFORE awakeFromNib, meaning before all objects are decoded, or I'm completely wrong ?

Link to comment
Share on other sites

 Share

×
×
  • Create New...