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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T05:17:01+00:00 2026-05-14T05:17:01+00:00

A minimal illustrative Xcode project for this is available on github . On my

  • 0

A minimal illustrative Xcode project for this is available on github.

On my UIWindow, when I add second (and subsequent) UITableView’s as subviews, they do not rotate properly, and thus appear sideways. This is only tested in the Simulator. Here’s a little code for you:

- (void)applicationDidFinishLaunching:(UIApplication *)application {
    ShellTVC* viewA = [[ShellTVC alloc] initWithTitle:@"View A"];
    ShellTVC* viewB = [[ShellTVC alloc] initWithTitle:@"View B"];

    // The first subview added will rotate to landscape correctly. 
    // Any subsequent subview added will not.

    // You may try this by various commentings and rearranging of these two statements.

    [window addSubview:[viewA tableView]];
    [window addSubview:[viewB tableView]];

    [window makeKeyAndVisible];
}

viewB appears sideways. Comment out the addSubview for viewB, and viewA appears correctly. Do that for viewA only, and viewB appears correctly.

I am not creating these UITableViewControllers via NIBs, though the UIWindow is.

In case you are wondering, ShellTVC is-a UITableViewController, and implements this method:

- (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
 return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
}

Also, I have set the UIInterfaceOrientation in the plist file to UIInterfaceOrientationLandscapeLeft.

Probably related — and unanswered — SO questions here and here.

  • 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-14T05:17:01+00:00Added an answer on May 14, 2026 at 5:17 am

    I think I figured out a way — possibly the right way — to do this.

    1. Create a “master” UIViewController subclass, which implements shouldAutorotate…, and add this as the only view on your window.
    2. To alternate between viewA or viewB, use the combination of dismissModalViewControllerAnimated: & presentModalViewController:animated: on this master view controller.

    Here’s some code:

    // this doesn't really do much but implement shouldAutorotate...
    @interface MasterViewController : UIViewController
    @end
    
    @implementation MasterViewController
    - (BOOL) shouldAutorotateToInterfaceOrientation(UIInterfaceOrientation)interfaceOrientation {
         return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
    }
    @end
    
    @interface MyAppDelegate : NSObject <UIApplicationDelegate> {
        MasterViewController* masterVC;
        UIViewController* activeTVC;
        UIViewController* onDeckTVC;
    }
    @end
    
    - (void)applicationDidFinishLaunching:(UIApplication *)application {
        UIViewController* masterVC = [[MasterViewController alloc] init];        
        activeTVC = [[ShellTVC alloc] initWithTitle:@"View A"];
        onDeckTVC = [[ShellTVC alloc] initWithTitle:@"View B"];
        [window addSubview:masterView.view];
        [window makeKeyAndVisible];
        [masterVC presentModalViewController:activeTVC animated:NO];
    }
    
    // you would call this to toggle between "View A" and "View B"
    - (void)toggleTVC {
        UITableViewController *hold = activeTVC;
        activeTVC = onDeckTVC;
        onDeckTVC = hold;
        [masterVC dismissModalViewControllerAnimated:NO];   
        [masterVC presentModalViewController:activeTVC animated:NO];
    }
    

    Why does this work?

    1. All orientation changes flow through view controllers, not views.

    2. As far as I can tell, the first view or subview that you add to your window gets some special sauce. If that view has a view controller, the window figures it out.

    That is, for the first subview only, you can think of this code:

    [window addSubview:masterVC.view];
    

    as doing something like this (not a real method!):

    [window addSubview:masterVC.view withViewController:masterVC];
    

    I don’t understand any more about it than that. I find the fact that I can do this with the first subview, but not others, supremely perplexing. More info welcomed, and please let me know if this helped you or not.

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

Sidebar

Ask A Question

Stats

  • Questions 371k
  • Answers 371k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer There's no reason for a public constructor for an abstract… May 14, 2026 at 6:57 pm
  • Editorial Team
    Editorial Team added an answer Save should not be part of business logic - it… May 14, 2026 at 6:57 pm
  • Editorial Team
    Editorial Team added an answer Instead of catch($e){ use catch (Exception $e) { see http://docs.php.net/language.exceptions May 14, 2026 at 6:57 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.