Pradhyuman sinh
Pradhyuman sinh

Reputation: 3928

UISplitview orientation not change in iOS 5 and iOS 5.1

I have using split view in my application.
When i run my application in iOS 6 simulator it rotates as per orientation changes and works well but when i run same application in iOS 5 or iOS 5.1 simulator and i change orientation of simulator but split view not changes as per orientation change.
I also add code

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown || interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}

-(BOOL)shouldAutorotate
{
    return YES;
}

And I add split view using following code - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return YES; }

above method in both Master View and Detail View.

And I added split view using following code

if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
     // obj_PageControlViewController = [[PageControlViewController alloc]initWithNibName:@"PageControlViewController-iPad" bundle:nil];

     MasterViewController *masterViewController = [[MasterViewController alloc] initWithNibName:@"MasterViewController_iPad" bundle:nil];
     UINavigationController *masterNavigationController = [[UINavigationController alloc] initWithRootViewController:masterViewController];

     DetailViewController *detailViewController = [[DetailViewController alloc] initWithNibName:@"DetailViewController_iPad" bundle:nil];
     UINavigationController *detailNavigationController = [[UINavigationController alloc] initWithRootViewController:detailViewController];

     masterViewController.detailViewController = detailViewController;

     self.splitViewController = [[UISplitViewController alloc] init];
     self.splitViewController.delegate = detailViewController;
     self.splitViewController.viewControllers = @[masterNavigationController, detailNavigationController];
     TabBarAppDelegate *appDelegate = (TabBarAppDelegate *)[[UIApplication sharedApplication] delegate];
     [appDelegate.window setRootViewController:self.splitViewController];

}

but it's not work. Any one can help me?

Upvotes: 2

Views: 1220

Answers (2)

sparrowman
sparrowman

Reputation: 81

In iOS5 and below you should use

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation

The one you posted above (shouldAutorotate) is for iOS6+

Upvotes: 0

matt
matt

Reputation: 534950

You say you added shouldAutorotateToInterfaceOrientation: but you didn't say where you added it. To get autorotation of a UISplitViewController in iOS 5.1 or earlier, you must supply shouldAutorotateToInterfaceOrientation: in the view controllers of both child view controllers of the split view controller (both the master and the detail view controllers).

That will work, assuming that the split view controller is the top-level (root) view controller of your application, as set up by the Master-Detail template.

Oh, and save yourself some trouble: in shouldAutorotateToInterfaceOrientation:, just return YES. On iPad, you always want to autorotate.

Upvotes: 4

Related Questions