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 7083731
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:12:52+00:00 2026-05-28T07:12:52+00:00

I have an application which has 5 tabs on a TabBarController. For simplicity sake

  • 0

I have an application which has 5 tabs on a TabBarController. For simplicity sake lets say they are Tab A, B, C, D, and E. Each tab takes the user to a TableViewController which is embedded in a Navigation controller. Each tab also has its own specific .h and .m files. The code for the most part is very similar between the 5 tabs. I want to do away with these 5 sets of class files and just use 1 set. This will make it much easier for me to make changes to the application (in 1 place instead of 5 places). How can I detect in the single implementation file which tab was selected? Once I know that I can put logic in place to render the tableview specifically for which tab was selected…

Another thing I should mention is that I need to detect the selected Tab in the TableViewController. The TabBarController is the point of entry for the application and I do not have a TabBarController subclass.

I tried this code in the TableViewController however it does not get accessed and/or used.

in .h file:

@interface MyController : UITableViewController <UITabBarDelegate>

in .m file:

- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item
{
    //NSLog(@"selectedIndex: %d", self.tabBarController.selectedIndex);

    NSLog(@"didSelectItem: %d", item.tag);
}
  • 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-28T07:12:52+00:00Added an answer on May 28, 2026 at 7:12 am

    Easy, You already have the solution!

    tabBarController

    A parent or ancestor that is a tab bar controller.
    (read-only)

    @property(nonatomic, readonly, retain) UITabBarController *tabBarController

    Discussion If the receiver is added to a tab bar controller, this property is the tab bar controller. If the receiver’s
    navigation controller is added to a tab bar controller, this property
    is the navigation controller’s tab bar controller. If no tab bar is
    present or the receiver is a modal view, this property is nil.

    That means that any viewController you add to a tab bar controller has this property filled in by the system.

    Then in the view controller you want for the tab you implement viewWillAppear

    -(void)viewWillAppear:(BOOL)animated{
        [super viewWillAppear:animated];
        NSUInteger selectedIndex = self.tabBarController.selectedIndex;
        switch (selectedIndex) {
            case 0:
                //configure me
                break;
            case 1:
                //configure me differently!!
                break;
    
            default:
                break;
        }
    }    
    

    In light of the comments this property of tabBarController doesn’t seem to be reliable.

    The problem you describe sounds like something that could solved by subclassing. Make a subclass of UIViewController for the code in common with each tab and then subclass your subclass for each tabs viewController to make modifications unique to the tab.

    Alternatively you could load each tab with the same class but a different xib. You can set properties on your view controller in the “user defined runtime attributes” section in interface builder. Then in the viewWillAppear block just check the property set by the xib on that instance.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My iPhone app is a Tab Bar Application, which has 5 tabs. In each
I have a UITabBar application, which has three tabs. The first tab has a
My application has a TabActivity which contains 4 tabs. Each tab contains the corresponding
I have an iphone application which has about 4 tabs. How do I force
We have a Flex application which has several 'pages' worth of content. Each time
I have created an application having tab activity which in turn has 5 different
I have made an application which has tabs like in HelloTabActivity, there is also
I'm a bit puzzeled, I have an application which has 5 tabs in tabHost.
I have an application which has 7 tabs with associated views and view controllers.
I have an application which has two Tabs. Both of these are ListFragments. The

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.