I am developing an application for iOS using swift. I have already set up one UIPageViewController successfully in my project, so I know how it works. But now I'm trying to set up a second PageViewController, and it just doesn't work - it doesn't throw any errors either, it just goes directly to black screen and doesn't even show any segues
What I have tried so far:
- Resetting the iOS simulator
- Reindexing the xcode files
- Restarting xcode
- Restarting my machine
None of these things have helped.
My code:
(BTW: This code is almost the exactly same as in my working UIPageViewController, the only difference is in the variables' names)
import UIKit
class SelectDestinationViewController: UIPageViewController, UIPageViewControllerDelegate, UIPageViewControllerDataSource {
var destinationViewControllers : [UIViewController] = []
override func viewDidLoad() {
super.viewDidLoad()
println("View did appear")
// Do any additional setup after loading the view.
self.delegate = self
self.dataSource = self
let firstView = storyboard?.instantiateViewControllerWithIdentifier("firstView") as FirstDestinationViewController
let secondView = storyboard?.instantiateViewControllerWithIdentifier("secondView") as SecondDestinationViewController
destinationViewControllers = [firstView, secondView]
for var index = 0; index < destinationViewControllers.count; ++index {
println("\(destinationViewControllers[index])")
}
let startingViewController = self.viewControllerAtIndex(0)
let viewControllers: NSArray = [startingViewController]
self.setViewControllers(viewControllers, direction: UIPageViewControllerNavigationDirection.Forward, animated: true, completion: {(done: Bool) in})
}
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
println("View will appear!")
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func viewControllerAtIndex(index:NSInteger) -> UIViewController {
return destinationViewControllers[index]
}
func pageViewController(pageViewController: UIPageViewController, viewControllerBeforeViewController viewController: UIViewController) -> UIViewController? {
var index = find(destinationViewControllers, viewController)!
if (index == 0) || (index == NSNotFound) {
return nil
}
index--
if index == destinationViewControllers.count {
return nil
}
return self.viewControllerAtIndex(index)
}
func pageViewController(pageViewController: UIPageViewController, viewControllerAfterViewController viewController: UIViewController) -> UIViewController? {
var index = find(destinationViewControllers, viewController)!
if index == NSNotFound {
return nil
}
index++
if index == destinationViewControllers.count {
return nil
}
return self.viewControllerAtIndex(index)
}
func presentationCountForPageViewController(pageViewController: UIPageViewController) -> Int {
return destinationViewControllers.count
}
func presentationIndexForPageViewController(pageViewController: UIPageViewController) -> Int {
return 0
}
}
All the prints are showing up in the console - but nothing else is happening. Does anyone know what the problem might be? Thank you in advance :)
Aucun commentaire:
Enregistrer un commentaire