故事板、UIViewController 和 UISplitViewController [英] Storyboard, UIViewController and UISplitViewController

查看:22
本文介绍了故事板、UIViewController 和 UISplitViewController的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试为 iPad 制作基于故事板的应用程序.在其中,我需要从开始屏幕 (UIViewController) 过渡到主屏幕 (UISplitViewController),然后再到全屏视图(再次是 UIViewController).

Trying to make storyboard based application for iPad. In it I need to transition from start screen (UIViewController) to main screen (UISplitViewController) and then to full-screen view (again UIViewController).

我在网络上看到了许多讨论(至少有几个 - 在 stackoverflow 上),指出 UISplitViewController 除了作为 RootViewController 之外,不能以任何其他方式用于基于 Storyboard 的应用程序.一些线程包含变通方法,还有替代 splitview (https://github.com/mattgemmell/MGSplitViewController)解决这个问题.

I saw a number of discussions on the web (at least several - on stackoverflow), stating that UISplitViewController can't be used in Storyboard based application any other way than being RootViewController. Some threads contain workarounds and there's also alternative splitview (https://github.com/mattgemmell/MGSplitViewController) to cope with this.

但我无法理解的是,为什么 Apple 文档中的说法恰恰相反.这是 链接 到 Apple 的 iOS 5.0 库中的章节.它指出:

But what I can't understand is why Apple documentation states quite the opposite. Here is the link to the chapter from Apple's iOS 5.0 Library. It states:

要将拆分视图控制器添加到应用程序的故事板:

To add a split view controller to your application’s storyboard:

  1. 打开应用的主故事板.
  2. 从库中拖出一个拆分视图控制器.这也会创建视图控制器用于拆分视图控制器的两个窗格.
  3. 对于每个拆分视图控制器包含的视图控制器,使用身份检查器设置视图控制器的类名.

要呈现拆分视图界面,​​请执行以下操作之一:

To present the split view interface, do one of the following:

  • 将其显示为第一个场景,通过选择场景并检查属性检查器下的是初始视图控制器"框.
  • 从另一个场景中显示它,向它添加一个模态转场.
  • 通过调用 performSegueWithIdentifier:sender: 方法来启动模态转场,以编程方式显示它.

我尝试了很多方法,但最后两个语句中描述的方法从未奏效.modal segue 和 performSegue... 都失败,出现众所周知的错误:

I was trying it in many ways, but approaches described in last two statements never worked. Both modal segue and performSegue... fail with well-known error:

*** 由于未捕获的异常NSInvalidArgumentException"而终止应用程序,原因:应用程序试图以模态方式呈现拆分视图控制器......"

"*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Application tried to present a Split View Controllers modally..."

谁能解释一下?这是 XCODE/iOS 5.0 中的错误还是文档中的错误?

Anyone able to explain that? Is this a bug in XCODE/iOS 5.0 or bug in documentation?

问候,彼得

推荐答案

根据此 Apple 文章,拆分视图控制器必须是根.这是一个片段:

According to this Apple article, the split view controller must be the root. Here is a snippet:

拆分视图控制器必须始终是您创建的任何界面的根.换句话说,您必须始终将 UISplitViewController 对象中的视图安装为应用程序窗口的根视图.拆分视图界面的窗格可能包含导航控制器、选项卡栏控制器或实现界面所需的任何其他类型的视图控制器.拆分视图控制器不能以模态呈现.

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. Split view controllers cannot be presented modally.

这篇关于故事板、UIViewController 和 UISplitViewController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆