我的应用程序开始时只有一个UIWindow. 我以编程方式将视图控制器添加到self.windowin 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];
showMainViewController删除 myViewController,创建一个UITabBarController并将其设置为窗口的主视图:
[self.myViewController.view removeFromSuperview];
self.myViewController = nil;
tabBarController = [[UITabBarController alloc] init];
...
[self.window addSubview:tabBarController.view];
[self.window makeKeyAndVisible];
问题:
所有视图控制器都为shouldAutorotateToInterfaceOrientation:. 旋转工作正常,myViewController但一旦tabBarController可见,旋转停止工作并且界面出现在肖像中。这种行为背后的原因是什么?
此外,在 iOS 4.x 中,UIWindow 具有 rootViewController 属性。这个属性的作用是什么?新模板使用rootViewController而不是[self.window addSubview:...]. 这是为什么?