Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6980505
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:01:41+00:00 2026-05-27T18:01:41+00:00

So I have a UIViewController that has a UITabBar in the view. I want

  • 0

So I have a UIViewController that has a UITabBar in the view. I want to pull down JSON and decided what tabs I want to add to the tab bar, so I need to be able to choose the tabs on runtime. I wanted to use the UITabBarController setViewControllers:animated: method to add to it a list of view controllers. However since I am doing this in a view controller I do not know how to gain access to the tab bar’s view controller. Here is my code …

Header

#import <UIKit/UIKit.h>

@interface HealthTicketTabController : UIViewController <UITabBarDelegate, UITabBarControllerDelegate> {
    NSArray *viewControllers;
    IBOutlet UITabBar *tabBar;
    UIViewController *selectedViewController;

    // How do I link this the the tabBar's view controller???
    UITabBarController *tabBarController;
}

@property (nonatomic, retain) NSArray *viewControllers;
@property (nonatomic, retain) IBOutlet UITabBar *tabBar;
@property (nonatomic, retain) IBOutlet UITabBarController *tabBarController;
@property (nonatomic, retain) UIViewController *selectedViewController;

@end

Source

- (id)init
{
    self = [super initWithNibName:@"HealthTicketTabView" bundle:nil];
    if (self)
    {   
        //Controllers for the tab view
        HealthCardController *card = [[HealthCardController alloc] init];
        MedicalExpensesController *medical = [[MedicalExpensesController alloc] init];

        //Tab bar items to be displayed in the tab bar
        card.tabBarItem = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemMostViewed tag:0];
        medical.tabBarItem = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemMostViewed tag:1];

        NSArray *array = [[NSArray alloc] initWithObjects:card, medical, nil];

        //Set the tab bar's view controllers to the list
        tabBarController.viewControllers = [NSArray arrayWithObjects:card, medical, nil];

        [array release];
        [card release];
        [medical release];
    }

    return self;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T18:01:41+00:00Added an answer on May 27, 2026 at 6:01 pm

    Found out that since I was using a UIViewController to control the UITabBar I need to set the tab bar’s delegate to the current UIViewController and handle the tab events in the current controller.

    Adding TabBarItems to the TabBar

    [self.tabBar setItems: tabBarItems animated:TRUE];
    

    Switching between ViewControllers

    - (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item
    {
        UIViewController *temp = [viewControllers objectAtIndex:item.tag];
        [self.selectedViewController.view removeFromSuperview];
        [self.view addSubview:temp.view];
        self.selectedViewController = temp;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a UIViewController that I want to load from a NIB that has
I have a root UIViewController subclass that has a UITabBar, (I'm not using UITabBarController)
I have a UIViewController that has a XIB. I don't want to get rid
I have a View that has a UIWebView, and an OptionsPane (Custom UIViewController with
I have a view hierarchy that has a UIViewController as Files Owner in the
I have a custom UIViewController subclass that handles all the view initialization by itself
I have a UIView associated with it's own UIViewController that I want to always
I have a UIPopOverController that shows a UIViewController with a UITableview in its view.
I have a UIViewController that has an UIPopoverController that has an UINavigationController then a
In my iPhone app I have a UIViewController that has a UITableView and another

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.