S B
S B

Reputation: 8384

shouldAutorotateToInterfaceOrientation is being called multiple times - is this normal?

My split view controller code:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    LeftViewController *hvc = [[[LeftViewController alloc] initWithNibName:nil bundle:nil] autorelease];    
    DetailViewController *dvc = [[[DetailViewController alloc] initWithNibName:nil bundle:nil] autorelease];
    UINavigationController *rootNav = [[[UINavigationController alloc] initWithRootViewController:hvc] autorelease];
    UINavigationController *detailNav = [[[UINavigationController alloc] initWithRootViewController:dvc] autorelease];
    UISplitViewController *svc= [[[UISplitViewController alloc] init] autorelease];
    [svc setViewControllers:[NSArray arrayWithObjects:rootNav, detailNav, nil]];
    svc.delegate = dvc;
    [window setRootViewController:svc];
    [self.window makeKeyAndVisible];
    return YES;
}

DetailViewController.m and LeftViewController.m both contain

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    NSLog(@"should rotate asked to detailviewcontroller");
    return YES;
}

On the iPad simulator, I can see these many calls to shouldAutorotateToInterfaceOrientation when the app just gets launched

should rotate asked to detailviewcontroller
should rotate asked to leftviewcontroller
should rotate asked to leftviewcontroller
should rotate asked to detailviewcontroller
...
should rotate asked to leftviewcontroller   // these two lines
should rotate asked to detailviewcontroller // are repeated 13 times
...
should rotate asked to leftviewcontroller
should rotate asked to detailviewcontroller

What could be the reason behind this? I must mention I am not changing orientation of the simulator

Upvotes: 2

Views: 1591

Answers (1)

magma
magma

Reputation: 8520

shouldAutorotateToInterfaceOrientation is meant to check whether your view supports a specific orientation or not.

It does not necessarily mean that your device is moving / being rotated.

You shouldn't worry about the implementation details that lead external entities to query your view controller multiple times, and just return the appropriate value for your views.

If you're interested in detecting device rotations, you might decide to rely on UIDeviceOrientationDidChangeNotification.

Upvotes: 1

Related Questions