2011-10-25 3 views
2

マイスプリットビューコントローラコード:shouldAutorotateToInterfaceOrientationが複数回呼び出されています - これは正常ですか?

- (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とLeftViewController.m両方がiPadのシミュレータで

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

が含まれているアプリはちょうど立ち上げますと、私はshouldAutorotateToInterfaceOrientationにこれらの多くの呼び出しを見ることができます

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 

この理由は何でしょうか。私は、シミュレータ

答えて

1

shouldAutorotateToInterfaceOrientationの向きを変えるわけではない、あなたのビューは、特定の方向性をサポートしているかいないかどうかを確認するためのものです言及する必要があります。

必ずしもデバイスが移動中/回転中であるとは限りません。

あなたはあなたのビューコントローラを複数回照会する外部エンティティを導く実装の詳細について心配し、自分の意見に適切な値を返すべきではありません。

あなたは、デバイスの回転を検出するに興味があるなら、あなたはUIDeviceOrientationDidChangeNotificationに依存することを決定するかもしれません。

+1

私は外部のエンティティが 'shouldAutorotateToInterfaceOrientation'を何度も呼び出すことができると理解します。しかし15回以上?トリガーは何ですか?ここで明らかに間違っていることがあれば、皆さんと二重にチェックしてみてください。 –

関連する問題