0

私のアプリケーションは、UIWindow. self.windowビュー コントローラーをinにプログラムで追加しますapplication:didFinishLaunchingWithOptions:

myViewController = [[UIViewController alloc] init:...];
...

[self.window addSubview:myViewController.view];
[self.window makeKeyAndVisible];

同時に、バックグラウンド プロセスを開始します。

[NSThread detachNewThreadSelector:@selector(startupOperations) toTarget:self withObject:nil];

次のstartupOperationsような外観:

NSAutoreleasePool *threadPool = [[NSAutoreleasePool alloc] init];

// Load data
...

// When your done, call method on the main thread
[self performSelectorOnMainThread:@selector(showMainViewController) withObject:nil waitUntilDone:false];

// Release autorelease pool
[threadPool release];

showMainViewControllermyViewController を削除し、 を作成しUITabBarControllerてウィンドウのメイン ビューとして設定します。

[self.myViewController.view removeFromSuperview];
self.myViewController = nil;

tabBarController = [[UITabBarController alloc] init];
...

[self.window addSubview:tabBarController.view];
[self.window makeKeyAndVisible];

質問:

すべてのビュー コントローラが に対して YES を返していshouldAutorotateToInterfaceOrientation:ます。回転は正常に機能しますmyViewControllerが、 が表示されるとすぐtabBarControllerに回転が停止し、インターフェイスが縦向きに表示されます。この動作の背後にある理由は何ですか?

また、iOS 4.x では、UIWindow に rootViewController プロパティがあります。このプロパティの役割は何ですか? 新しいテンプレートでは、rootViewController代わりに[self.window addSubview:...]. 何故ですか?

4

1 に答える 1

1

かなり奇妙です。シンプルなタブバーベースのプロジェクトで「ビューフロー」をシミュレートしてみましたが、初期コントローラーを削除し、タブバーコントローラーのビューをサブビューとして追加した後、自動回転が効果的に機能します。

機能しなかった唯一の条件はself.window、削除しなかった2番目のサブビューが含まれていた場合です。実行した瞬間に確認していただけますか

 [self.window addSubview:tabBarController.view];

self.window.subviewコンテンツとは何ですか?

それでも解決しない場合は、UITabBarControllerとを初期化する方法を質問で共有できますUITabBarか?

あなたの2番目の質問に関しては、あなたが言うrootViewControllerように、ウィンドウに属するすべてのビューのルートコントローラーです:

ルート ビュー コントローラーは、ウィンドウのコンテンツ ビューを提供します。ビュー コントローラーをこのプロパティに割り当てると (プログラムまたは Interface Builder を使用して)、ビュー コントローラーのビューがウィンドウのコンテンツ ビューとしてインストールされます。ウィンドウに既存のビュー階層がある場合、新しいビューがインストールされる前に古いビューが削除されます。

ソース

それを使用することもできますが、すでに に割り当てていることに注意してapplicationDidFinishLaunchingください。そうしないと、「手動で」サブビューを追加し、後でこのプロパティを変更しても、明示的に追加したサブビューは削除されません。

于 2011-07-11T13:35:04.817 に答える