The issue is this. I have a PageViewController as my root view controller. Initialising the first page using SetViewControllers in the ViewDidLoad block of the PageViewController class works, as does the flipping back and forth of pages using the page’s gesture recognizers. This root view controller is available application-wide via the AppDelegate.
I wanted to add the ability to return to the first page from anywhere in the book, so created a public method in my PageViewController class that simply called the SetViewControllers method. While this appears to work, I’ve noticed certain quirks. Music that is looping in the background (again, an AVAudio object declared in the AppDelegate) is restarted and the ViewDidLoad block doesn’t fire until the page is turned again using the gesture recognizers.
I tried the same thing using GetNextViewController but that simply throws a null reference exception for the PageViewController reference. I’m assuming there is some relationship between the controls I’m not grasping, perhaps something to do with the PageViewController’s DataSource. I have tried delegating this to a class that overrides the default methods, as well as using Mono’s this.pageViewController.GetNextViewController = delegate(method signature) syntax to no avail.
Does anyone have any insights as to what my problem here is?
Edit: Code for AppDelegate.cs can be viewed here: https://gist.github.com/1747537 and for PageViewController.cs here: https://gist.github.com/1747559.
I can see several issues in your code:
PageViewControlleris already the root controller in your app, there is no need to callAddSubview()anywhere.UIViewControllerand then encapsulate aUIPageViewController.You should either inherit fromUIPageViewControlleror have no inheritance at all (if it is true as Dimitri says theUIPageViewControlleris not meant for subclassing).ReturnToFrontPage()could be a method of your AppDelegate instead of your subclassedUIPageViewController.In short: don’t inherit anything in your case. Use a plain UIPageViewController and make the
ReturnTpFrontPage()a method of your AppDelegate, then it should all be a walk in the park.