这是一个关于it技术的Xcode项目,可以在github上找到。
当我将第二个及后续的UITableView添加为子视图时,它们无法正确旋转,因此显示为侧卧。这仅在模拟器中测试过。下面是一些代码:
- (void)applicationDidFinishLaunching:(UIApplication *)application {
ShellTVC* viewA = [[ShellTVC alloc] initWithTitle:@"View A"];
ShellTVC* viewB = [[ShellTVC alloc] initWithTitle:@"View B"];
// The first subview added will rotate to landscape correctly.
// Any subsequent subview added will not.
// You may try this by various commentings and rearranging of these two statements.
[window addSubview:[viewA tableView]];
[window addSubview:[viewB tableView]];
[window makeKeyAndVisible];
}
视图B显示为侧面。将viewB的addSubview注释掉,viewA就会正确显示。只对viewA这样做,viewB就会正确显示。
我没有通过NIB创建这些UITableViewControllers,但UIWindow是通过NIB创建的。
如果你想知道,ShellTVC是一个UITableViewController,并实现了这个方法:
- (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
}
另外,我已经在plist文件中将UIInterfaceOrientation设置为UIInterfaceOrientationLandscapeLeft。