Search code examples
iphoneobjective-cios6uipageviewcontroller

Custom method for UIPageviewController datasource


I want to implement one custom method for uipageviewcontroller datasource that will turn to page at index

something like this

- (void) pageViewController:(PageViewController *)pageViewcontroller willTurnToPageAtIndex:(NSUInteger)currentIndex 

I don't know if this is correct way of implementing custom method for uipageviewcontroller datasource.


Solution

  • You can add whatever methods you like to your data source class. Methods that are considered public should also be defined in the header file.

    But that's not what you're asking. You're asking: how can I get UIPageViewController to call it?

    The short version is: you can't.

    While your method has a nice, readable signature, to the compiler it's no different to:

    - (void) pageViewController:(PageViewController *)pageViewcontroller banana:(banana*)banana;
    

    There's no way that the controller could be expected to know what to do with it.

    I'm afraid, in general, you have to use the methods that are published.

    There are some exceptions. For example, sometimes there is no delegate method but you can subscribe to a notification. Or maybe there's another delegate to use? In your case I would expect a "will do something" method to be on the delegate rather than the data source.