gpt4 book ai didi

ios - 使用 UIPageViewController 在多个 View Controller 之间滑动

转载 作者:搜寻专家 更新时间:2023-10-31 19:31:24 24 4
gpt4 key购买 nike

我的 UIPageViewController 根本不工作。我想要做的是在 UIPageViewController 中切换 2 个 View Controller 。我已经按照此处的指南进行操作但失败了。 Using UIPageViewController with swift and multiple view controllers .第一个 View Controller 看起来很成功,但是当我尝试滑动到第二个 View Controller 时,它会抛出此错误消息。我已经正确设置了所有标识符。

fatal error: unexpectedly found nil while unwrapping an Optional value

从这里开始

func pageViewController(pageViewController: UIPageViewController, viewControllerBeforeViewController viewController: UIViewController) -> UIViewController? {

let identifier = viewController.restorationIdentifier
let index = self.identifiers.indexOfObject(identifier!) // error message here

//if the index is 0, return nil since we dont want a view controller before the first one
if index == 0 {

return nil
}

//decrement the index to get the viewController before the current one
self.index = self.index - 1
return self.viewControllerAtIndex(self.index)

}

主 Storyboard

enter image description here

源代码:https://github.com/datomnurdin/RevivalxSwiftPageViewController

最佳答案

崩溃发生在尝试访问 View Controller 的 restorationIdentifier 时。你使用了 ! 来打开它,但它是 nil ;作为第一个解决方案,在 Storyboard中设置 restorationIdentifier

enter image description here

In general, use ! to unwrap a value only if you're sure it's not nil (by adding a if statement just before).

关于ios - 使用 UIPageViewController 在多个 View Controller 之间滑动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28734103/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com