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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T01:50:06+00:00 2026-06-19T01:50:06+00:00

I’m new to Xcode and starting a universal app. In the iPad version I

  • 0

I’m new to Xcode and starting a universal app. In the iPad version I want to re-use the main section for different search forms.

I want the user to see a completely different form in the section to the right (see image) for each button on the left menu.

I’m working programmatically.

enter image description here

What’s the best way to change the content in this situation? (keeping in mind performance and coding complexity)

EDIT: This is a standard tabbed application, not a split view. Could I have a new view controller and .xib for each form and then change which one is displayed by embedding them in a UIView or UIWindow on this screen?

  • 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-19T01:50:07+00:00Added an answer on June 19, 2026 at 1:50 am

    You’ve hit upon the right answer in your edit. From what I understand the buttons on the side are analagous to another tab bar controller, but nested within your main tab bar controller?

    You might as well follow the same pattern, since it is a familiar one. Your search view controller should act as a container view controller, which would have an array of view controllers representing each form option.

    As you switch between the options, add/remove the appropriate view controller views from your view hierarchy (using addSubview) and view controller hierarchy (using the code in “Adding and removing a child” in the link). The view controller hierarchy is important to ensure that viewDidAppear and so forth is called on your child controllers.

    As an illustration, I’ve created a simple demo project where the main view controller has a set of buttons, each linked to the same action, and an array of contained view controllers. The contained view controllers will be held inside a subview, called container in this example. This would be the size of the right hand area in your screenshot above.

    The child controllers are set up as follows in viewDidLoad of the container view controller:

    @property (strong, nonatomic) IBOutletCollection(UIButton) NSArray *buttons;
    @property (weak, nonatomic) IBOutlet UIView *container;
    
    @property (nonatomic,strong) NSArray *viewControllers;
    @property (nonatomic, strong) UIViewController *currentChild;
    
    @end
    
    @implementation JRTViewController
    
    - (void)viewDidLoad
    {
        [super viewDidLoad];
        // Do any additional setup after loading the view, typically from a nib.
    
        for (UIButton *button in self.buttons)
            [button addTarget:self action:@selector(buttonTapped:) forControlEvents:UIControlEventTouchUpInside];
    
        NSMutableArray *children = [NSMutableArray new];
    
        for (int i = 0; i < 4; i++)
        {
            ContainedViewController *child = [ContainedViewController new];
            child.name = [NSString stringWithFormat:@"Form %d",i + 1];
            [children addObject:child];
        }
    
        self.viewControllers = [children copy];
        [self buttonTapped:self.buttons[0]];
    }
    

    Here I’ve used four instances of the same view controller class – all it has is a label which indicates which form you are selecting. Really you’d have different classes for each one. I’ve also “selected” the initial view controller by sending the action method for the first button. The action method does this:

    - (IBAction)buttonTapped:(UIButton *)sender
    {
        NSUInteger index = [self.buttons indexOfObject:sender];
        if (index != NSNotFound)
            self.currentChild = self.viewControllers[index];
    }
    

    Which selects the appropriate VC from the view controller array. The setter method does this:

    -(void)setCurrentChild:(UIViewController *)currentChild
    {
        if (currentChild == _currentChild) return;
    
        // Remove the old child
        [_currentChild willMoveToParentViewController:nil];
        [_currentChild.view removeFromSuperview];
        [_currentChild removeFromParentViewController];
        [_currentChild didMoveToParentViewController:nil];
    
        // Add the new one
        [currentChild willMoveToParentViewController:self];
        [self.container addSubview:currentChild.view];
        NSDictionary *views = @{@"view":currentChild.view};
        [self.container addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"|[view]|" options:0 metrics:nil views:views]];
        [self.container addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[view]|" options:0 metrics:nil views:views]];
        [self addChildViewController:currentChild];
        [currentChild didMoveToParentViewController:self];
        _currentChild = currentChild;
    }
    

    Which sets up the view controller hierarchy, adds in the view and uses constraints to make it fill the container.

    In this example I’ve hardcoded in four buttons and four child view controllers as I was demonstrating the addition and switching of child view controllers. In reality you’d make it more like a tab bar controller where you assign an array of view controllers and the container would make its own array of buttons.

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

Sidebar

Related Questions

I want use html5's new tag to play a wav file (currently only supported
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I am confused How to use looping for Json response Array in another Array.
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I have a French site that I want to parse, but am running into
I'm interested in microtypography issues on the web. I want a tool to fix:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
This could be a duplicate question, but I have no idea what search terms
We're building an app, our first using Rails 3, and we're having to build

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.