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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T15:57:30+00:00 2026-06-17T15:57:30+00:00

I have added Two Tabs in my app, to load two view controller using

  • 0

I have added Two Tabs in my app, to load two view controller using these tabs

  • Tab1 : Home
  • Tab2 : Favourite

so I have written below code to achieve this

In app Delegate

AppDelegate.h

@class ViewController,FavViewController;

@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;

@property (strong, nonatomic) ViewController *viewController;
@property (strong, nonatomic) FavViewController *favViewController;

@property (strong, nonatomic) UITabBarController *tabBarController;

@end

AppDelegate.m

       @implementation AppDelegate

        @synthesize window = _window;
        @synthesize viewController;
        @synthesize favViewController;
        @synthesize tabBarController;

        - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
        self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 

        baseTabBarController = [[UITabBarController alloc]init];

        baseTabBarController.delegate=self;

        viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil]; 
        UINavigationController *homeView = [[UINavigationController alloc]initWithRootViewController:viewController];  

        favViewController = [[FavViewController alloc] initWithNibName:@"FavViewController" bundle:nil];
        favViewController.title = @"My Favourite";
        UINavigationController *favouriteView = [[UINavigationController alloc] initWithRootViewController:favViewController];  


        NSArray *controllers = [NSArray arrayWithObjects:homeView,favouriteView, nil];  
        baseTabBarController.viewControllers = controllers; 

        [self.window addSubview:baseTabBarController.view]; 
        [self.window makeKeyAndVisible];    

        return YES;
    }

    - (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)selectedViewController
{

    if (tabBarController.selectedIndex == 0) {




   }else if (tabBarController.selectedIndex == 1) {

    [(FavViewController *)[(UINavigationController*)selectedViewController topViewController] getData];

    }else if (tabBarController.selectedIndex == 2) {

        NSLog(@"2");
    }


}

and here is the Result Screen I am getting

enter image description here

So Where I am having trouble in this..

If I switch to the next screen my First tab doesn’t load First Screen (Home screen) instead just stay on current screen.

Let me try with example

There are four screens in my app let say A, B, C, D

I have added Tabs for A and C screens,those are available in whole app
(All screen).

Now if I’ll start app and go A ->B->C -> D and press on Home Tab (A)
it doesn’t load Screen A, instead just stay on Current screen

but good thing is if i do same process with another tab C (My
Favourite) it loads correct screen.

Edit: I have implemented didSelectViewController method as @sanjit suggested me but in that I not able distinguish, which tab is tapped this time?

I would be really appreciate!! if someone can point me on right direction

  • 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-17T15:57:31+00:00Added an answer on June 17, 2026 at 3:57 pm

    Use Tabbar delegate and using parameter instance of uiviewcontroller call poptorootviewcontroller method. Hope it may work for you. Try the following code

    - (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
    {
    UINavigationController *navController = (UINavigationController*)tabBarController.selectedViewController;
    
    [navController popToRootViewControllerAnimated:YES];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using a JTabbedPane in my application. I have added two tabs which
I am using a UiTableView in our application.We have two tabs in controller one
I have created two tabs, say TAB1 and TAB2. For TAB1, i have loaded
I have made an app in which i am using Two Tabs , First
I have added Two Factor Authentication to my Mobile ASP.Net Web App. When the
I have three tabs . I have added functionalities to the first two tabs
I am creating a web application using backbone.js. I have two tabs. Tab 1
I have added two gesture recognizers to a view. One will handle the view
I have an app with one main TabBarController containing two tabs that control two
I have added two buttons to navigation controller one inplace of right button and

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.