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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T11:26:11+00:00 2026-05-20T11:26:11+00:00

I have a root view controller which has few buttons. On click of these

  • 0

I have a root view controller which has few buttons. On click of these button, I shown up a tab bar controller with each controller showing the table view controller. I have achieved this. So basically, for each table view controller I have a dedicated class. To go ahead, I replaced the tab bar controller, and added the segmented controller to the navigation title view.

The question is how can I set the view based on the selected index. I am able to set the navigation title to be segmented control but on select I am unable to set the view.

Below is what i have achieved so far.
Note: What matters is a running code, I would do that code optimization later on. I dont want to hidde views. I want to call different view controller class.

RootViewController class (on click of the button, i call the first view controller. So that I can set the segment controller:

-(IBAction) pushSegmentController: (id) sender 
{

    NSLog(@"My Location Button being clicked/touched") ;

    FirstViewController *firstViewController = [[FirstViewController alloc] init] ;
    [self.navigationController pushViewController:firstViewController animated:YES];

    // Releae the view controllers
    [firstViewController release];

}

IN FirstViewController class:

-(void)viewDidLoad {

    [super viewDidLoad];

    NSArray *viewControllers = [self segmentViewControllers];


    self.segmentedControl = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:@"Table1", @"Table2"]];

    self.navigationItem.titleView = segmentedControl;

    [self.segmentedControl addTarget:self 
                              action:@selector(indexDidChangeForSegmentedControl:) 
                    forControlEvents:UIControlEventValueChanged];

    self.segmentedControl.selectedSegmentIndex =  0;
}

-(void)indexDidChangeForSegmentedControl:(UISegmentedControl *)aSegmentedControl {

    NSUInteger index = aSegmentedControl.selectedSegmentIndex;

    if(index ==0) {
    UIViewController *table1Controller = [[AustraliaViewController alloc] initWithStyle:UITableViewStylePlain];
         **???? HOW SHOULD I SET THE VIEW OVER HERE... AS ITS A PART OF THE NAVIGATION CONTROLLER**
    }
    else { }
}

Note: I have tried using this option:

[navigationController setViewControllers:theViewControllers animated:NO];

But this option doesnt give me the right result. How should I go ahead with the same as I want to call a view controller class and set its view based on the selected index.

  • 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-20T11:26:11+00:00Added an answer on May 20, 2026 at 11:26 am

    You probably don’t want to have one view controller with different views depending on the button index, especially since you already have view controllers for your different screens.

    If you want the table view controller to be pushed onto your navigation controller, so it will have a back button that gets you back to FirstViewController, use

    -(void)indexDidChangeForSegmentedControl:(UISegmentedControl *)aSegmentedControl {
        NSUInteger index = aSegmentedControl.selectedSegmentIndex;
    
        UIViewController *newViewController = nil;
        if(index ==0) {
            newViewController = [[AustraliaViewController alloc] initWithStyle:UITableViewStylePlain];
        } else {
            newViewController = [[YourOtherViewController alloc] initWithStyle:UITableViewStylePlain];
        }
        [self.navigationController pushViewController:newViewController animated:YES];
    }
    

    If you’d rather have it slide in from the bottom and you want to handle setting up all necessary user interface (e.g. a dismiss button), replace that last line with

        [self presentModalViewController:newViewController animated:YES];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an iPhone app which has a tabBarController as the root view controller
I have a root UIViewController which has a property called webView. WebView is a
I have a xib with a view which contains two views which each contain
I have an app with a navigation controller as the root view. There are
I have an iPhone app with a UITabBar, and each tab has a unique
I am using a machine on which I do not have root access and
Currently I have a root-level repository set up for each project, like so: Project1
I have a root UIViewController subclass that has a UITabBar, (I'm not using UITabBarController)
I have a view containing a UIWebView which is loading a google map (so
I have written a subclass of UIViewController which creates a view programmatically, instead of

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.