I'm using a UIPageViewController to display various text files. My app uses the Xcode template for a page-based app.
At the moment, when a new file is loaded the controller displays the old text until a page is turned. It then displays the new text, so the data is being loaded properly. What I'd like the controller to do is display the first page of the new file immediately upon loading.
I've defined a notification that's sent when a new text file is loaded. What should my page view controller do when it receives this notification?
I found a solution, for the Xcode template code at least. Have the RootViewController respond to a notification posted when a new file is loaded. Then put this code into the function called when the notification is received:
let startingViewController: DataViewController = self.modelController.viewControllerAtIndex(0, storyboard: self.storyboard!)!
let viewControllers = [startingViewController]
self.pageViewController!.setViewControllers(viewControllers, direction: .forward, animated: false, completion: done in })
This code isn't mine: I copied and pasted it from the viewDidLoad function of RootViewController. So far, it works: the first page of the new text is displayed immediately upon being loaded. I just hope I haven't bypassed any important code that will come back to bite me.