我无法让UISplitViewController在我已编写iPhone部分的通用应用程序中工作。作为一种故障排除方法,我决定从一个新项目开始,只是尝试做一个导致问题的动作,但它仍然存在。
如果我创建一个通用应用程序并在iPad控制器中创建一个拆分视图(在XIB或代码中),那么它显示为黑色(除非我设置了背景颜色)。如果我在仅限iPad的应用程序中执行此操作,则显示正常。
如果有人可以自己测试一下,看看他们是否得到同样的东西,或者告诉我哪里出错了,我会很感激。
我得到的是黑屏,而不是拆分视图。相同的代码适用于仅限iPad的项目。我做错了什么,或者配置错了什么?
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
UISplitViewController *split = [[UISplitViewController alloc] initWithNibName:nil bundle:nil];
UIViewController *vc1 = [[UIViewController alloc] initWithNibName:nil bundle:nil];
vc1.view.backgroundColor = [UIColor redColor];
UIViewController *vc2 = [[UIViewController alloc] initWithNibName:nil bundle:nil];
vc2.view.backgroundColor = [UIColor blueColor];
split.viewControllers = [NSArray arrayWithObjects:vc1, vc2, nil];
[window addSubview:split.view];
[window makeKeyAndVisible];
[vc1 release];
[vc2 release];
[split release];
return YES;
}
答案 0 :(得分:3)
首先,您不应在didFinishLaunchingWithOptions中释放拆分视图。将它添加到您的界面(在UIWindow下)并仅在dealloc上释放它。二,子类UISplitViewController如下:
@interface MySplitViewController : UISplitViewController
{
}
@end
@implementation MySplitViewController
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
@end
第三,你的didFinishLaunchingWithOptions应如下所示:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
split = [[MySplitViewController alloc] init];
UIViewController *vc1 = [[UIViewController alloc] init];
vc1.view.backgroundColor = [UIColor redColor];
UIViewController *vc2 = [[UIViewController alloc] init];
vc2.view.backgroundColor = [UIColor blueColor];
split.viewControllers = [NSArray arrayWithObjects:vc1, vc2, nil];
[window addSubview:split.view];
[window makeKeyAndVisible];
[vc1 release];
[vc2 release];
return YES;
}