0
votes

I am a beginner in programming in iOS. I have a iOS application that has two classes(with xib), firstviewcontroller and secondviewcontroller. I want to add a tab bar to switch between these view controllers. if I for example add a tab bar to the first view, how to connect the views to the tab bar? Its just there, doing nothing..

2
can you post some code? Or if you set up the tab bar using interface builder, a screenshot of the xibs?Ariel

2 Answers

0
votes

This assumes that you want the tab bar as the main interface of your app.

  • In your app delegate, create a subclass of UITabBarController:

    UITabBarController *myTbc = [UITabBarController alloc] init];

  • Create instances of your two view controllers and add them to an NSArray

    NSArray *tabsArray = @[firstVC, secondVC];

  • Set that NSArray as the viewControllers property of the tab bar controller

    [myTbc setViewControllers:tabsArray];

  • Set the tab bar controller as the app's root view:

    self.window.rootViewController = theTbc;