The number of view controllers provided (0) doesn't match the number required (1) for the requested transition
Asked Answered
A

0

1

we have used the page view controller to show the swipe to instruct the user to login instruction, we are facing core foundation crash and below is the stack trace and code snippet:

StackTrace:

Fatal Exception: NSInvalidArgumentException
The number of view controllers provided (0) doesn't match the number required (1) for the requested transition
keyboard_arrow_up
Fatal Exception: NSInvalidArgumentException
0  CoreFoundation                 0x2362a8518 __exceptionPreprocess
1  libobjc.A.dylib                0x2354839f8 objc_exception_throw
2  CoreFoundation                 0x2361b2c70 -[NSCache init]
3  UIKitCore                      0x2620c1e94 -[UIPageViewController _validatedViewControllersForTransitionWithViewControllers:animated:]
4  UIKitCore                      0x2620c2a2c -[UIPageViewController _setViewControllers:withCurlOfType:fromLocation:direction:animated:notifyDelegate:completion:]


extension HelpPageViewController: UIPageViewControllerDataSource {
    func pageViewController(_ pageViewController: UIPageViewController, viewControllerBefore viewController: UIViewController) -> UIViewController? {
        guard let viewControllers = pageViewControllers, let index = viewControllers.index(of: viewController), index > 0 else { return nil }
        return viewControllers[index - 1]

    }

    func pageViewController(_ pageViewController: UIPageViewController, viewControllerAfter viewController: UIViewController) -> UIViewController? {
        guard let viewControllers = pageViewControllers, let index = viewControllers.index(of: viewController), index < viewControllers.count - 1  else { return nil }
        return viewControllers[index + 1]
    }
}
        override func viewDidLoad() {
            super.viewDidLoad()
            dataSource = self
            pageViewControllers = helpType?.viewControllers
            if let helpViewControllers = pageViewControllers {
                DispatchQueue.main.async{
                    if let firstViewController = helpViewControllers.first {
                        self.setViewControllers([firstViewController], direction: .forward, animated: false, completion: nil)
                    }
                }
            }
        }

    var helpType:HelpType?
    var pageViewControllers:[UIViewController]?
}
Addictive answered 3/3, 2020 at 6:42 Comment(3)
You need to referent this link - #17334246 - It will help to identify your mistake and I hope will over come.Intelligibility
My guess is that either helpType is nil or helpType?.viewControllers is nil or empty.Lamented
Thanks, @Paulw11. I have set the nil value for both helpType as well as helpType?.viewControllers. I am not getting crashAddictive

© 2022 - 2024 — McMap. All rights reserved.