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

  • Home
  • SEARCH
  • 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 6735869
In Process

The Archive Base Latest Questions

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

My project is a view based project to start off. So app delegate launches

  • 0

My project is a view based project to start off.

So app delegate launches as per normal.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window.rootViewController = self.viewController;
    [self.window makeKeyAndVisible];
    return YES;
}

Then my first viewcontroller is called and it shows two UITextFields so the user can enter their credentials and log on.

When that succeeds I call another view controller in which I add a UINavigationController and a UITabBarController to the view. As can be seen below.

- (void)viewDidLoad
{
[super viewDidLoad];

UINavigationController *localNavigationController;
tabBarController = [[UITabBarController alloc] init];
NSMutableArray *localControllersArray = [[NSMutableArray alloc] initWithCapacity:2];


Hello *firstViewController;
firstViewController = [[Hello alloc] init];
localNavigationController = [[UINavigationController alloc] initWithRootViewController:firstViewController];
[localNavigationController.tabBarItem initWithTitle:@"Test" image:[UIImage imageNamed:@"tabBarIcon.png"] tag:1];
//[localNavigationController.tabBarItem initWithTabBarSystemItem:UITabBarSystemItemDownloads tag:1];
firstViewController.navigationItem.title=@"New Requests";

[localControllersArray addObject:localNavigationController];
[localNavigationController release];
[firstViewController release];


Test *secondViewController;
secondViewController = [[Test alloc] init];
localNavigationController = [[UINavigationController alloc] initWithRootViewController:secondViewController];
[localNavigationController.tabBarItem initWithTitle:@"Test" image:[UIImage imageNamed:@"tabBarIcon.png"] tag:2];
secondViewController.navigationItem.title=@"Existing";


[localControllersArray addObject:localNavigationController];
[localNavigationController release];
[secondViewController release];


// load up our tab bar controller with the view controllers
tabBarController.viewControllers = localControllersArray;

// release the array because the tab bar controller now has it
[localControllersArray release];


// add the tabBarController as a subview in the window
[self.view addSubview:tabBarController.view];

}

This seems to work ok, so far. There was a problem off both the Navbar and Tabbar being dropped to low by the height of the status bar, but that was corrected once i hid the status bar.

Is there any reason I should not do things this way? Is it bad practice or will i run into some problems with it down the road?

I could set up both the Navbar and the Tabbar from the app delegate and just hide them both during the log-on screen. That’s the only other option I see.

I appreciate any feedback that you guys can offer. I feel nervous about the results of what I have done so far, expect it might blow up in my face.

Many Thanks,
-Code

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

    You should generally not directly add the views of UINavigationController and UITabBarController as subviews of your own view controllers. This kind of ‘view controller containment’ is tricky to get right unless you use the new iOS 5 APIs.

    The reason is that the actual view controllers will not receive certain important messages like viewDidAppear: and rotation messages. You will notice strange rotation bugs and other weird issues cropping up. You can forward these methods yourself from the parent view controller and things will work OK, but in your case you have no need to do this because you’re just trying to show a standard tab bar controller.

    Generally you should have one view controller set up as the UIWindow‘s root view controller. This is normally a UINavigationController, UITabBarController, etc. The parent UIWindow will send rotation events and other messages to this controller. The standard ‘container’ controllers like UITabBarController will then forward these messages to their children so everything works correctly.

    If I were you, I would always have the tab bar controller as the window’s root view controller. When your app starts (i.e. in application:didFinishLaunchingWithOptions:), create an empty tab bar controller and set it up as the root view controller:

    - (BOOL)application:(UIApplication *)application
        didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
        // create a basic empty tab bar controller
        self.tabBarController = [[[UITabBarController alloc] init] autorelease];
        // ...
    
        // Set up the window's root view controller
        self.window.rootViewController = tabBarController;
    
       // ...
    }
    

    Now, whenever you present stuff on the screen, it should be a child of the root view controller, in your case the tab bar controller.

    So once the root view controller is set up, you can check to see if the user is already logged in. If they are, you can then set up your navigation controller and the tab items, and add them to the tab bar controller.

    If the user is not logged in, you can show your login view controller over the top of the tab bar controller using presentModalViewController:animated::

    - (BOOL)application:(UIApplication *)application
        didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
        // ...
    
        // Set up the window's root view controller
        self.window.rootViewController = tabBarController;
    
        if (isUserLoggedIn()) {
            [self setupTabsAndStuff];
    
        } else {
            LoginViewController *loginVC = [[[LoginViewController alloc] init] autorelease];
            [self.tabBarController presentModalViewController:loginVC animated:NO];
        }
    
        // ...
    }
    

    The animated:NO will cause the login screen to be immediately visible after starting the app with no animation.

    Once the user enters correct details you can again call your setupTabsAndStuff method and dismiss the login view controller again.

    So to summarize:

    • Rather than having your own UIViewController into which you place the tab bar controller’s view, just use the tab bar controller directly.
    • Install the tab bar controller as the window’s root view controller. The tab bar controller will then correctly forward rotation events and other special messages to the view controllers it contains.
    • Always present views and view controllers as children of the root view controller. If you need to show something full-screen use presentModelViewController:animated
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i am developing a iphone application in a view-based project,(not navigation) however i would
I made a fresh view-based app project which has a MyProjectViewController.xib. Then I created
I create an application base on view based Application project . so i have
I created a project using the View-Based Application template. In my mainViewController : -
Greetings, I have a view based application project where I have created an NSObject
I have developed a view based project in Xcode. It is successfully running in
I am working on a view-based project. My first view is a UIView where
I have a view based project working with a UINavigationController. The RootViewController performs operations
I created a View-Based project in Xcode, but I find no Localizeable.strings file for
New view based project in XCode Go to main.xib and view.xib respectively In each

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.