Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to connect dataSource outlet of a Page View Controller using Storyboard in Interface Builder

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?

like image 293
Terrence Tan Avatar asked Nov 01 '12 05:11

Terrence Tan


2 Answers

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

self.delegate=self;
self.dataSource=self;
like image 167
Weel Avatar answered Sep 20 '22 01:09

Weel


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.

like image 43
JulianSymes Avatar answered Sep 20 '22 01:09

JulianSymes