iOS Developer Library

Developer

UIKit Framework Reference UIPageViewControllerDataSource Protocol Reference

Options
Deployment Target:

On This Page
Language:

UIPageViewControllerDataSource

Inherits From


Not Applicable

Import Statement


Swift

import UIKit

Objective-C

@import UIKit;

Availability


Available in iOS 5.0 and later

The UIPageViewControllerDataSource protocol is adopted by an object that provides view controllers to the page view controller on an as-needed basis, in response to navigation gestures.

The data source implementation is free to handle this responsibility in any way that is appropriate for your application. In many cases, it should look at the view controller passed to it, determine what content to display, and create the view controllers as they are needed. You may find it helpful to include information such as the page number in the view controller, to simplify the task of determining what content to display.

If both of the methods in Supporting a Page Indicator are implemented and the page view controller’s transition style is UIPageViewControllerTransitionStyleScroll, a page indicator is visible. Both of these methods are called after the setViewControllers:direction:animated:completion: method is called. After gesture-driven navigation, these methods are not called. The index is updated automatically and the number of view controllers is expected to remain constant.

  • Returns the view controller before the given view controller. (required)

    Declaration

    Swift

    func pageViewController(_ pageViewController: UIPageViewController, viewControllerBeforeViewController viewController: UIViewController) -> UIViewController?

    Objective-C

    - (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController

    Parameters

    pageViewController

    The page view controller

    viewController

    The view controller that the user navigated away from.

    Return Value

    The view controller before the given view controller, or nil to indicate that there is no previous view controller.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 5.0 and later

  • Returns the view controller after the given view controller. (required)

    Declaration

    Swift

    func pageViewController(_ pageViewController: UIPageViewController, viewControllerAfterViewController viewController: UIViewController) -> UIViewController?

    Objective-C

    - (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController

    Parameters

    pageViewController

    The page view controller

    viewController

    The view controller that the user navigated away from.

    Return Value

    The view controller after the given view controller, or nil to indicate that there is no next view controller.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 5.0 and later

  • Returns the number of items to be reflected in the page indicator.

    Declaration

    Swift

    optional func presentationCountForPageViewController(_ pageViewController: UIPageViewController) -> Int

    Objective-C

    - (NSInteger)presentationCountForPageViewController:(UIPageViewController *)pageViewController

    Parameters

    pageViewController

    The page view controller.

    Return Value

    The number of items to be reflected in the page indicator.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 6.0 and later

  • Returns the index of the selected item to be reflected in the page indicator.

    Declaration

    Swift

    optional func presentationIndexForPageViewController(_ pageViewController: UIPageViewController) -> Int

    Objective-C

    - (NSInteger)presentationIndexForPageViewController:(UIPageViewController *)pageViewController

    Parameters

    pageViewController

    The page view controller.

    Return Value

    The index of the selected item to be reflected in the page indicator.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 6.0 and later