【问题标题】:Best practice for displaying modal view above UISplitViewController在 UISplitViewController 上方显示模态视图的最佳实践
【发布时间】:2011-03-19 16:07:50
【问题描述】:

基于 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 并让它在纵向模式下全屏显示而不为根控制器添加菜单项吗?

【问题讨论】:

  • 我做到了(正如我在描述中指出的那样。)我确定我遗漏了一些东西......加载后它也可以工作。即,如果我添加一个在 viewWillAppear 之后 0.01 秒执行的方法调用,那么它可以工作(但你确实看到了转换。)

标签: iphone ipad uisplitviewcontroller


【解决方案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];
}

【讨论】:

  • 在使用故事板的应用程序中,从 AppDelegate 调用 presentModalViewController 时似乎不起作用。
猜你喜欢
  • 2011-12-18
  • 1970-01-01
  • 2012-01-16
  • 2016-10-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-09-16
相关资源
最近更新 更多