15

According to Apple's documentation here, we should be able to add a Page View Controller into the storyboard and then optionally set the data source by connecting the outlets.

Creating a Page View Controller Interface Using a Storyboard

The Page-Based Application Xcode template creates a new project with a page view controller as the initial scene.

To add a page view controller to an existing storyboard, do the following:

  1. Drag a page view controller out of the library. Add a page view controller scene to your storyboard.
  2. In the Attributes inspector, set up the appropriate options.
  3. Optionally, set a delegate, a data source, or both by connecting the corresponding outlets.
  4. Display it as the first view controller by selecting the option Is Initial View Controller in the Attributes inspector (or present the view controller in your user interface in another way.)

I then defined a UIPageViewController subclass like so

@interface DetailsPageViewController : UIPageViewController <UIPageViewControllerDataSource>

but then when I tried to connect the data source outlet, it does not highlight the controller or allow to connect it. I have also tried implementing UIPageViewControllerDataSource on other controllers but I have the same problem of not being able to connect the outlet.

Can anyone help?

Terrence Tan
  • 532
  • 5
  • 10

2 Answers2

6

I failed to find a way to do it in IB. Have to use the following instead:

self.delegate=self;
self.dataSource=self;
Weel
  • 132
  • 2
  • 7
  • I used your answer but also have to set the inital view controller via setViewControllers: of UIPageViewController class to make it shows properly. – haxpor Feb 06 '15 at 02:47
  • I see the same thing in xcode 7.3. Don't see anyway to make IB allow you to make the connection. Don't really understand the other answer as everything is already in the storyboard, IB just doesn't allow me to make the connections. – John Fowler Mar 30 '16 at 19:39
5

Note that the Apple documentation states that UIPageViewController is not normally subclassed. Your UIPageViewControllerDataSource does not need to be a subclass of a View Controller. You can make it a subclass of NSObject.

Normally only things that appear on the storyboard, namely UI elements, are listed in the document outline that appears to the left of the storyboard (provided it has not been hidden). If your delegate/datasource is not already there, you can put it there, by dragging an 'Object' (yellow cube) into the document outline, in the appropriate scene.

Then click on the Object that you just added, and use the Identity Inspector pane to alter its concrete class to your data source class. It's then available to be used as the target of a connection in the normal way by dragging a line from the Connections inspector onto it.

JulianSymes
  • 2,135
  • 22
  • 24
  • Have you actually tried the UIPageViewController. If you have and know the answer to my question, please provide specifically how you did it in the context of my question. – Terrence Tan Apr 03 '14 at 13:29
  • @TerrenceTan Yes I have. Have you tried my solution? – JulianSymes Apr 04 '14 at 10:47
  • I have edited my answer. I hope this provides greater clarity. – JulianSymes Apr 04 '14 at 11:43
  • Thanks for your edited answer. I can follow it now by adding the 'Object'. – Terrence Tan Aug 23 '14 at 05:26
  • [Apple's documentation on UIPageViewController](https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIPageViewControllerClassReferenceClassRef/index.html) now says: *"This class is generally used as-is but **may be subclassed in iOS 6 and later**."* – Pang May 14 '15 at 08:03