- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我第一次尝试让 UIPageViewController 工作,但每当我尝试设置它的 View Controller 时,我似乎都遇到了麻烦。
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
let leftViewController = storyboard?.instantiateViewControllerWithIdentifier("LeftViewController")
let rightViewController = storyboard?.instantiateViewControllerWithIdentifier("RightViewController")
let viewControllerArray: [UIViewController] = [leftViewController!, rightViewController!]
self.setViewControllers(viewControllerArray, direction: .Forward, animated: true, completion: nil)
}
每次我到达 setViewControllers()
方法时,应用程序都会在 AppDelegate
文件中崩溃,并显示以下错误日志:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException',
reason: 'The number of view controllers provided (2) doesn't match the number
required (1) for the requested transition
23 UIKit 0x0000000103a06610 UIApplicationMain + 171
24 PageViewTesting 0x000000010300649d main + 109
25 libdyld.dylib 0x0000000105a3292d start + 1
26 ??? 0x0000000000000001 0x0 + 1)
libc++abi.dylib: terminating with uncaught exception of type NSException
目前我的 Storyboard中有一个 UIPageViewController
和两个 UIViewControllers
。我已经仔细检查过它们的 ID 对于 instantiateViewControllerWithIdentifier()
方法也是正确的。
关于我收到此错误的原因有什么想法吗?
最佳答案
来自 UIPageViewController
的类引用:
// setViewControllers:direction:animated:completion:
func setViewControllers(_ viewControllers: [UIViewController]?,
direction direction: UIPageViewControllerNavigationDirection,
animated animated: Bool,
completion completion: ((Bool) -> Void)?)
The view controllers passed to this method are those that will be visible after the animation has completed. Use a data source to provide additional view controllers to which users navigate.
对于单 View Controller View 模式,代码中使用的方法.setViewControllers
只需要一个 View Controller (但是,在数组形式上)。参数采用数组 [UIViewController]
有点令人困惑,但这是为了在使用 spine(中间) View 时使用 PageViewController 的 doubleSided
属性。
When defining a page view controller interface, you can provide the content view controllers one at a time (or two at a time, depending upon the spine position and double-sided state)
...
UIPageViewControllerSpineLocationMid
Spine in the middle or the screen.
Two view controllers are displayed at a time.
您打算使用书脊中 View 吗?在这种情况下,您可以发送两个 View Controller ,否则,您应该只发送一个并使用数据源添加其他 View Controller 。
关于ios - 如何防止 UIPageViewController 的 setViewControllers 方法崩溃?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34466847/
仅限 Swift 我创建了一个功能齐全的 UIPageViewController,其中包含 3 个不同的 UIViewController,是否可以在其中一个 UIViewController 中创
我正在寻找一种解决方案,其中我将一个 uipageviewcontroller 嵌入到另一个 uipageviewcontroller 中,因此当我尝试滑动最后一个 viewcontroller 时内
我想调整我的 UIPageViewController 以像图像中那样工作,目前 1b 可以去 2a 等。我需要什么像图片中那样锁定方向?我忘记了什么还是我使用了错误的逻辑。任何提示都会有很大帮助!
我在从 UIPageViewController 打开 View 并返回到 PageViewController 上的同一页面时遇到问题。我当前的设置是一个教程,您可以滚动页面查看教程。在第二页上,它
几个小时以来,我一直在努力解决这个问题,我一定是误解了 UIPageViewController 的工作原理。 我有 5 个设置屏幕(加载到 UIPageViewController 中的独立 Vie
我正在尝试将 UIPageViewController 的 UIPanGestureRecognizer 分配给不同的(自定义) View ,以便用于页面切换的平移手势仅适用于屏幕的特定区域。代码基本
我的 UIPageViewController 有一个大问题。我想使用部分和子部分在我的应用程序中呈现内容。因此,我创建了 UIPageViewController 的“两个” 实例 - 水平(红色)
我正在尝试创建一个只占据屏幕一部分的滚动页面 View Controller 。我已经使用 Storyboard 和 ContainerView 对象成功地做到了这一点,但我现在需要复制以编程方式创建
我正在使用 UIPageViewController 来浏览页面(UIViewController 数组)。我将页面 View Controller 推到顶部导航 Controller 上。 当我启动
我在 Xcode 4 中使用基于页面的应用程序模板来加载 PDF 页面并在隐藏的文本框上创建一个 UITextView,以便用户可以写笔记。 到目前为止,我已经完成了所有工作,但是当我添加 UITex
我正在使用带有 transitionStyle 的 UIPageViewController UIPageViewControllerTransitionStyleScroll和导航定位UIPageV
我是 iPhone 应用程序开发新手,需要在我正在开发的应用程序中显示 PDF 文件。我想使用 UIPageViewController 因为它允许分页等。到目前为止,我还无法弄清楚如何将内容加载到
谁能告诉我,如何使用 UIPageViewController 在我的背景图像而不是 View 边界周围制作阴影? 换句话说,我有一个“不规则的背景图像”,其边界看起来像波浪。当我从一个页面转到另一个
我的 UIPageViewController 在 iOS 5 中运行良好。但是当 iOS 6 出现时,我想使用新的滚动过渡样式(UIPageViewControllerTransitionStyle
我已经在这上面花了几个小时了。我已使用 UIPageViewControllerNavigationOrientationHorizontal 初始化了 UIPageViewController,
在我的应用程序中,我使用 UIPageViewController (PVC) 以及 UIPageViewControllerTransitionStylePageCurl 过渡样式和 UIPageV
我有一个 UIPageViewController显示带有 Transition style scroll 的图像.我要处理tap和 pan手势所以为了做到这一点,我做了一个小技巧,把另一个 view
我有一个 UIPageViewController ( 委托(delegate))管理 3 个 UIViewController . 要从第二个 View 转到第三个,我必须点击一个按钮,否则第二个
我正在展示一个简单的 UIPageViewController 并向其中添加一些非常简单和愚蠢的 subview Controller 。当 UIPageViewController 被解雇时,我正在
我有一个带有动态变化数据源的 UIPageViewController - viewControllerAfterViewController 和 viewControllerBeforeViewCo
我是一名优秀的程序员,十分优秀!