Stumpp
Stumpp

Reputation: 289

iOS change view with tab bar

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..

Upvotes: 0

Views: 596

Answers (2)

TimD
TimD

Reputation: 8522

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;

Upvotes: 0

Related Questions