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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T18:13:45+00:00 2026-06-17T18:13:45+00:00

I have a UIViewController called DashBoardViewController that acts as delegate for a UITabBar. In

  • 0

I have a UIViewController called DashBoardViewController that acts as delegate for a UITabBar. In its xib I have placed a UITabBar with 3 UITabBarItem.

Each of these items activate a different View Controller, let’s call them ViewController1, ViewController2, ViewController3

DashBoardViewController is supposed to show ViewController1 and select the first bar on loading, so in my initWithNibName I have what follows:

...
ViewController1* vc = [[ViewController1 alloc] initWithNibName:@"ViewController1" bundle:nil];
[self.view addSubview:vc.view]; 
self.currentViewController = vc;
...

I implement the UITabBarDelegate having something as follows:

if (item == viewController1Item) {
    ViewController2 *vc2 = [self.childrenControllers objectAtIndex:1];


    [self.currentViewController.view removeFromSuperview];
    [self.view addSubview:vc2.view];
    self.currentViewController = vc2;


} ...

Problem
The View Controller in the first UITabBarItem always works as expected, extending it to the full size of thew view.
However, in the second and following tabs, this doesn’t happen: the view doesn’t extends. This shows if, for example, I align a tab with the bottom in the ViewController2 XIB: this will not be at the bottom when viewed inside the UITabBarItem.

Note
Please note that this is not related to the XIB: if I invert ViewController1 and ViewController2, it will be ViewController1 the one failing to extend. It’s related to the UITabBarItem.

Ideas
Possibly, this depends by the way I addSubview when I call the DashBoardViewController’s initWithNibName. But I can’t find a way to explain this.

Other details
All the XIB are set with “Size = none”.

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

    I can’t really speak to the way you have your XIB setup without seeing it, but I can make a couple of suggestions.

    The behaviour that you’re trying to implement by removing & adding subviews to DashBoardViewController should really be handled by a UITabBarController. This provides a UITabBar, a view for your content and handles the logic of switching between UIViewControllers while keeping layout sane and being part of the SDK.

    If for some reason you can’t, or don’t want to use a UITabBarController, I’d suggest implementing a viewWillLayoutSubviews method on your DashBoardViewController, like so:

    - (void)viewWillLayoutSubviews
    {
        if( self.currentViewController )
        {
            self.currentViewController.view.frame = self.view.bounds;
        }
    }
    

    Maybe also try adding the self.currentViewController.view.frame = self.view.bounds; line after you’ve swapped ViewControllers too, for good measure. This will make sure that the frame of your current ViewController’s view is always sized to fill the bounds of DashBoardViewController’s view.

    This isn’t the ‘Proper’ way to do it though, I’d really recommend using a UITabBarController if you can, since you don’t know how much else of UITabBarController you’ll end up re-implementing if you start rolling your own controller.

    Any further problems will most probably be to do with the internal layout of your sub-ViewControllers, rather than their size / position in DashBoardViewController’s view.

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

Sidebar

Related Questions

I have created a UIViewController class called MyViewController with a UIImageView in its XIB
I have a UIViewController (called AdjustViewController ) that presents another UIViewController (called SourcePickerViewController )
I have a UIViewController called HomeViewController and it has a model that contains an
I have a UIViewController called simple ViewController . I want it so that when
So I have a UIViewController subclass called MyTabBarViewController that has a UIScrollView. Inside of
I have a UIViewController that materializes its view in loadView (i.e. no nib). Per
Still I couldn't understand completely how these delegate methods are getting called. I have
I have a UIViewController subclass that loads a bunch of images for each cell
I have a subclass of UIViewController called SurveyQuestion. I use an array of these
I have a UIViewController with its own .xib, and I want to use a

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.