Forum Xamarin Xamarin.iOS

Can anyone expand on the UIPageViewController example in the Xamarin iOS API? I have a few questions

TrevorYokumTrevorYokum USMember ✭✭

I have been using the documentation/C# example listed here. In my app, I need to add functionality for the user to be able to scroll left and right through various pages. This is exactly what I'm looking for; however, the documentation is slightly unclear. In both the GetPreviousViewController and GetNextViewController methods, this line of code is written

var currentPage = referenceViewController as PageController;

but there is no previous language or code to specify what a PageController is. So, what is a page controller? Is it just a UIViewController with an index field?

And, finally, at the top of the code sample, we have pvController.DataSource = new PageDataSource(pages); -- I know exactly what this does, but what is the pages array? Is it an array of UIViewControllers or PageControllers? As far as I can tell, the only thing that PageController is used for is the .Index field in each of the GetPrevious and GetNext methods.

Can someone help me out here? It would be much appreciated :-)

Best Answer

  • JGoldbergerJGoldberger USMember, Forum Administrator, Xamarin Team, University Xamurai
    edited March 2017 Accepted Answer

    @TrevorYokum

    I found a sample that might help explain things:
    https://github.com/minsed/xamarin-ios-pageviewcontroller-example

    Looking it over, yes, the PageController would be a UIViewController with an index field (and some other fields) added. In the sample they name it ContentViewController. So these are your pages. I would imagine you would use that as the base class for the actual pages (UIViewControllers).

    and pages would be a list of PageControllers. Note this in the API docs:
    List<PageController> pages;

    so pages is a List of PageControllers. The example I linked does something a bit different here, it uses the same ContentViewController for all pages and then just populates it with different title and image when it is instantiated in the ViewControllerAtIndex method.

Answers

  • JGoldbergerJGoldberger USMember, Forum Administrator, Xamarin Team, University Xamurai
    edited March 2017 Accepted Answer

    @TrevorYokum

    I found a sample that might help explain things:
    https://github.com/minsed/xamarin-ios-pageviewcontroller-example

    Looking it over, yes, the PageController would be a UIViewController with an index field (and some other fields) added. In the sample they name it ContentViewController. So these are your pages. I would imagine you would use that as the base class for the actual pages (UIViewControllers).

    and pages would be a list of PageControllers. Note this in the API docs:
    List<PageController> pages;

    so pages is a List of PageControllers. The example I linked does something a bit different here, it uses the same ContentViewController for all pages and then just populates it with different title and image when it is instantiated in the ViewControllerAtIndex method.

  • TrevorYokumTrevorYokum USMember ✭✭

    @JGoldberger -- thanks so much Jon, it worked perfectly and I just applied what you were saying to my solution. Thanks for the speedy response, too. Very helpful.

Sign In or Register to comment.