gpt4 book ai didi

ios - 页面 View Controller 出错

转载 作者:行者123 更新时间:2023-11-28 09:57:40 27 4
gpt4 key购买 nike

我不断收到以下错误:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'The number of view controllers provided (0) doesn't match the number required (1) for the requested transition.'

我不确定我在 PageViewController 中做错了什么可能会导致此错误。我也试着按照提供的答案 here .但是,该解决方案对我没有帮助,因为我不确定我的哪段代码可能导致了问题。我是 Swift 的新手,所以非常感谢任何帮助。

更新:我发现是 setViewController 导致了这个问题,删除后它就消失了。但是,为什么这会引起问题?谢谢!

    var pageViewController: UIPageViewController!

override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
self.pageViewController = harishStoryboard.instantiateViewControllerWithIdentifier("ViewController1") as! UIPageViewController
self.pageViewController.dataSource = self
let allViewControllers = [harishStoryboard.instantiateViewControllerWithIdentifier("ViewController2") as! ViewController2, harishStoryboard.instantiateViewControllerWithIdentifier("ViewController3") as! ViewController3, harishStoryboard.instantiateViewControllerWithIdentifier("ViewController4") as! ViewController4, harishStoryboard.instantiateViewControllerWithIdentifier("ViewController5") as! ViewController5, harishStoryboard.instantiateViewControllerWithIdentifier("ViewController6") as! ViewController6, harishStoryboard.instantiateViewControllerWithIdentifier("ViewController7") as! ViewController7]
let viewControllers = NSArray(object: allViewControllers)
self.pageViewController.setViewControllers(viewControllers as? [UIViewController], direction: .Forward, animated: false, completion: nil)
self.addChildViewController(pageViewController)
self.view.addSubview(self.pageViewController.view)
self.pageViewController.didMoveToParentViewController(self)
}

最佳答案

这不是页面 View Controller 的工作方式。您不传递多个 View Controller ,而只传递一个或最多两个。请参阅苹果文档:

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) or as-needed using a data source. When providing content view controllers one at a time, you use the setViewControllers:direction:animated:completion: method to set the current content view controllers. To support gesture-based navigation, you must provide your view controllers using a data source object.

我假设您需要基于手势的导航,因此您需要实现页面 View Controller 委托(delegate)和数据源。谷歌上有很多页面 View Controller 教程。

关于ios - 页面 View Controller 出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34468196/

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