Here I Created UIPageViewController by programmatically. When I load more than one ViewController to UIPageViewController. App crashed.
Check my code below.
class PageVC: UIPageViewController {
let colors = [UIColor.green, UIColor.red, UIColor.blue, UIColor.black]
var pages: [UIViewController] = []
override var spineLocation: UIPageViewController.SpineLocation {
return .min
}
override func viewDidLoad() {
super.viewDidLoad()
self.isDoubleSided = true
colors.forEach({
let page = UIViewController()
page.view.backgroundColor = $0
pages.append(page)
})
self.view.backgroundColor = UIColor.red
self.setViewControllers(pages, direction: UIPageViewController.NavigationDirection.forward, animated: true, completion: nil)
}
}
Getting Error like below.
Help me to fix this issue.
I faced the same issue from another prospective. I was trying to change spine location from
options
when initializing theUIPageViewController
. Following Apple Documentation i tried to wrap up the preferred spine location into anNSNumber
and set it as the value for thespineLocation
key in the options dictionary but the application always crash. Not sure why...Actually, the only way i know to change the spine location programmatically is by returning the chosen one in the delegate method
spineLocationFor orientation
. You have to create another ViewController and add the custom PageViewController as a child. I know it's not the exact answer to your question but hope it helps. By code, using a UIPageViewController:.