2012-04-05 103 views
21

我有一个使用导航控制器的XCode iPad项目。我试图让一个按钮来推UISplitViewController到导航堆栈,但得到这个错误:iOS:UISplitViewController无法推送到UINavigationController

Split View Controllers cannot be pushed to a Navigation Controller

原来UISplitViewController不UINavigationController的发挥很好。但是,我仍然需要在单击此按钮时显示分割视图控制器。我该怎么做呢?而且,同样重要的是,如何制作后退按钮,以便用户可以返回到导航控制器?

回答

28

要显示SplitViewController,您需要使用setRootViewController。这是因为SplitViewController需要成为根视图控制器。

从苹果公司的文档:

A split view controller must always be the root of any interface you create. In other words, you must always install the view from a UISplitViewController object as the root view of your application's window. The panes of your split-view interface may then contain navigation controllers, tab bar controllers, or any other type of view controller you need to implement your interface.

要回到你需要使用setRootViewController回到前面的页面。当我将iPhone应用程序转换为通用程序时,遇到了这个问题,并最终使用iPhone的导航控制器和iPad版本的setRootViewController。这是一个有点无赖,因为你不能很好地动画without a bit of fudging

+0

我该如何使用setRootViewController?谷歌告诉我这是一个UIWindow的方法,但我无法弄清楚在哪里找到一个UIWindow实例。 – 2012-04-05 16:29:41

+2

您需要从应用程序委托中获取属性,如下所示:MyAppDelegate * appDelegate =(MyAppDelegate *)[[UIApplication sharedApplication] delegate];然后[appDelegate.window setRootViewController:shareSelectViewController]; – glenstorey 2012-04-05 19:58:11

+0

非常感谢你! – 2013-04-22 22:44:07