3

基于 SplitViewController 模板创建一个新应用程序,它在拆分视图中运行良好。

我的主屏幕是一个非拆分视图的“菜单”。我正在尝试找出以模态方式在 splitViewController 上方添加此“mainMenu”的最佳实践。(然后要么将其他非拆分视图推到 mainMenu 上方,要么将其移除以显示和使用 UISplitViewController。)

我努力了:

[self.navigationController presentModalViewController:mainMenu animated:NO];

[self presentModalViewController:mainMenu animated:NO];

在 rootViewController 和 detailViewController 的 viewWillAppear 和 viewWillLoad 方法中。在这两种情况下,代码执行都没有错误,但是 mainMenu 没有出现,常规的 detailViewController 和 rootViewControllers 出现了。

(我确实创建了一个从 main.xib 文件中的 navigationController 到 detailView navigationController 的出口,但这并没有改变任何东西。)

我能够通过使用来完成这项工作,它有效,但似乎不正确。

iPad_Prototype_SplitAppDelegate *delegate = (iPad_Prototype_SplitAppDelegate *) [   [UIApplication sharedApplication] delegate];

[delegate.splitViewController.view addSubview:mainMenu.view];
[delegate.splitViewController.view bringSubviewToFront:mainMenu.view];

我看到很多回复说要以模态方式呈现这样的覆盖视图,但我似乎无法在 splitViewController 设置中找到正确的位置或配置。感谢您的任何帮助或见解。

最后,这种方法是否错误,我是否应该只换掉 detailViewController 并让它在纵向模式下全屏显示而不为根控制器添加菜单项?

4

1 回答 1

1

AppDelegate 中的 splitViewController 是否像示例一样,这会有所帮助吗?

//AppDelegate.m
- (BOOL)application:(UIApplication *)application 
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{  

MyController *myCont = [[MyController alloc] initMainMenu];
// mess around with myCont.view.modalPresentationStyle;

[myCont setModalDelegate:self]; 
// Create a delegate (<ModalControllerDelegate>) to dismiss view when done

[self.splitViewController presentModalViewController:myCont animated:NO];
[myCont release];
}

// for completion sake
-(void)modalViewDismiss:(MyController *)modalView {
    [self.splitViewController dismissModalViewController:YES];
}
于 2011-07-25T14:56:13.937 回答