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

  • Home
  • SEARCH
  • 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 9071965
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T18:03:16+00:00 2026-06-16T18:03:16+00:00

I’m new in iOS development and this may be a very basic question- in

  • 0

I’m new in iOS development and this may be a very basic question- in my app i’ve 5 VC with UITabBarController on each VC. I’m handling tab bar item click by-

- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item
{
    switch (item.tag)
    {
        case 0:
        {
            vc1 = [[VC1 alloc] initWithNibName:@"VC1" bundle:nil];
            [self.view addSubview:vc1.view];
            [tabbarObj setSelectedItem:[tabbarObj.items objectAtIndex:0]];
        }
            break;
        case 1:
        {
            vc2 = [[VC2 alloc] initWithNibName:@"VC2" bundle:nil];
            [self.view addSubview:vc2];
        }
            break;
        case 2:
        {
            vc3 = [[VC3 alloc] initWithNibName:@"VC3" bundle:nil];
            [self.view addSubview:vc3];
        }
            break;
        case 3:
        {
            [tabbarObj setSelectedItem:[tabbarObj.items objectAtIndex:3]];
        }
            break;
        case 4:
        {
            vc5 = [[VC5 alloc] initWithNibName:@"VC5" bundle:nil];
            [self.view addSubview:vc5];
        }
            break;
        default:
            break;
    }
}

and i know this is not a right way to handle tab bar because every time when i click on a tab bat item it will add a subView on current view.
Can anybody suggest me a better way?Thanks.

  • 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-06-16T18:03:17+00:00Added an answer on June 16, 2026 at 6:03 pm

    in Your Appedelegate.m file Make changes in didFinishLaunchingWithOptions Method

     tabBar_Controller = [[UITabBarController alloc] init];
        NSMutableArray *localControllersArray =[[NSMutableArray alloc]initWithCapacity:2];
    
    
    
        firstViewController = [[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil];
    
        nav = [[UINavigationController alloc] initWithRootViewController:firstViewController];
    nav.tabBarItem.title = @"item1";
        nav.navigationBar.barStyle = UIBarStyleBlack;
       [localControllersArray addObject:nav];
                [self setNav:nil];
    
        secondViewController = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];
    
        nav = [[UINavigationController alloc] initWithRootViewController:secondViewController];
        nav.tabBarItem.title = @"item2";
               [localControllersArray addObject:nav];
    
        [self setNav:nil];
     tabBar_Controller.viewControllers = localControllersArray;
       tabBar_Controller.delegate = self;
        tabBar_Controller.selectedIndex = 0;
    [self.window addSubview:tabBar_Controller.view];
    

    To Access Some properties after Your ViewController is Selected Use the following Code.

    - (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewControllers
    {
        NSUInteger index=[[tabBarController viewControllers] indexOfObject:viewControllers];
    
        switch (index) {
    
    
            case 0:
            {
    
                NSLog(@"selected 1");
    
                break;
            }
            case 1:
    
              {
                NSLog(@"selected 2");
                        break;
            }
            default:
                break;
        }
    
    
    }
    

    For Changing Background image of tabbar Controller you can use Following Code.

    - (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewControllers{
        NSUInteger index=[[tabBarController viewControllers] indexOfObject:viewControllers];
    
        switch (index) {
            case 0:
                [tabBarController.tabBar setBackgroundImage:[UIImage imageNamed:@"tab_act21.png"]];
    
                break;
            case 1:
                [tabBarController.tabBar setBackgroundImage:[UIImage imageNamed:@"tab_act22.png"]];
                break;
            case 2:
                [tabBarController.tabBar setBackgroundImage:[UIImage imageNamed:@"tab_act23.png"]];
                break;
            default:
                break;
        }
    
        return YES;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
This could be a duplicate question, but I have no idea what search terms
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I want use html5's new tag to play a wav file (currently only supported
I have this code to decode numeric html entities to the UTF8 equivalent character.
We're building an app, our first using Rails 3, and we're having to build
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString

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.