Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

steps to add tabbarcontroller to AppDelegate using Interface Builder in XCode 4.2 Empty Application template

while I'm stuck at this question I cannot find the right steps to add a UITabBarController to the AppDelegate (not programatically) but by using interface builder for the "Empty Application" template, I tried to add a new empty xib file, then dropped uitabbarcontroller into it, but there is no way to link it (from IB) to AppDelegate !! i.e. when I move the blue line from tabbarcontroller object (in document outline) to File's Owner, interface builder shows only the "Delegate" option in the shown list so there is no IBOutlet option in there.

so, what are the exact steps for adding a tabbarcontroller and connect it to appDelegate using the interface builder way (for the Empty Application template, using XCode 4.2 and IOS 5 SDK) ?

step1: create new Empty Application template project.

... waiting for the next steps...

thanks so much in advance.

like image 410
JAHelia Avatar asked Nov 20 '11 11:11

JAHelia


People also ask

How to Add tab bar item?

To add a tab, first drag a new View Controller object to the storybard. Next control-drag from the tab bar controller to new view controller and select view controllers under Relationship Segue . Your tab bar controller will update with a new tab.

How to Add tabs in xcode?

Just add two more view controllers to your project, and then control drag from the tab bar controller to the view controllers to make segues to them. Make sure you select "Relationship-viewControllers" when the list pops up. Tabs will automatically be added.


1 Answers

Step 1: create new Empty Application template project.
Step 2: add

@property (nonatomic, strong) IBOutlet UITabBarController *tabBarController;
@property (nonatomic, strong) IBOutlet UIWindow *window;

in your app delegate. (dont forget to synthesize these) Step 3: change this line in your app delegate:

@interface AppDelegate : NSObject <UIApplicationDelegate, UITabBarControllerDelegate>

Step 4: modify this method

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[self.window addSubview:[self.tabBarController view]];
[self.window makeKeyAndVisible];
return YES;
}  

Step 5: create a new empty xib. Drag a tab bar controller on to it as well as an empty object.
Set the empty object's class to AppDelegate. Set Files Owner to UIApplication.

Step 6: drag the 'delegate' property from your files owner on to your appdelegate class and drag the tab bar outlet from you appdelegate class to your tabbarcontroller

Step 7: Add a window and drag the 'window' connection from your appdelegate to the window.

Step 8: Dont forget to go into the project settings and set the main-base nib file to the new xib you created.

Thats it. Hope I didn't miss anything.

like image 91
SEG Avatar answered Nov 14 '22 21:11

SEG