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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:59:57+00:00 2026-05-25T14:59:57+00:00

I programmatically create a tab bar with two view controllers like the following code.

  • 0

I programmatically create a tab bar with two view controllers like the following code. I find it hard to clean the memory when I do not need the tab bar any more. Apple’s documentation is very limited about releasing tab bar controller. I don’t know how to release all the view controllers in the ‘viewControllers’ array. I tried to print out the retain count and found x & y’s retainCount is as high as 5.

@interface X:UIViewController
@interface Y:UIViewController

@interface Z: UIViewController {
  UITabBarController *tabBar; 
}
@end

@implementation Z
-(IBAction)openTabBarUp{
  UITabBarController *tabBar = [[UITabBarController alloc] init];

  X *x = [[X alloc] init];
  Y *y = [[Y alloc] init];

  tabBar.viewControllers = [NSArray arrayWithObjects: x, y, nil];
  [self.view addSubView: tabBar.view];

}

this is how I try to release the memory:

-(IBAction)removeTabBar{
  [tabBar.view removeFromSuperView];
  [tabBar release];
  tabBar = nil;
}

Thanks

Leo

  • 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-25T14:59:58+00:00Added an answer on May 25, 2026 at 2:59 pm
    -(IBAction)openTabBarUp{
      tabBar = [[UITabBarController alloc] init];
    
      X *x = [[X alloc] init];
      Y *y = [[Y alloc] init];
    
      tabBar.viewControllers = [NSArray arrayWithObjects: x, y, nil];
      [self.view addSubView: tabBar.view];
    
    }
    

    You done need UITabBarController *tabBar = [[UITabBarController alloc] init]; in the openTabBarUp method as you already have an instance of it declared in the header file. You can release the tabBar using [tabBar release]; but Apple insists to add the tabBarController as the rootview of your main window and not as part of any view controller.

    UPDATE

    The Apple reference documents on UITabBarController states

    When deploying a tab bar interface, you must install this view as the
    root of your window. Unlike other view controllers, a tab bar
    interface should never be installed as a child of another view
    controller.

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

Sidebar

Related Questions

I have written the code programmatically for my tab bar in my table view.The
i want to add buttons on to my tab bar programmatically in my view...
I have created tab bar programmatically in the view controller. In my application, Initially
I have a my views and controllers set up like so. A Tab/Bar controller
I would like to programmatically create a gloss effect on an Image, kinda like
I have a TabBar which has been created programmatically. In the view controllers of
I have to programmatically create a task for a user that was not explicitly
I have a tab bar controller that I have created programmatically, named TPastJourneyTabbar .
I have a three view tab bar app the second view of which I
I am creating app based on UTabbarController. I have creates that tab bar programmatically.

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.