Setting up an Xcode project as a PageViewController control is one way to achieve this, however, if you want to include a PageViewController in your existing storyboard, you can also do this.
If you drag the PageViewController Scene onto your storyboard and attach the cache, you can click on this PageViewController. However, it seems that there are some errors in the storyboard to correctly configure PageViewController, for example, you cannot connect a delegate and data source.
A simple way is to simply bind the delegate / data source in the init method:
- (instancetype) initWithCoder:(NSCoder *)aDecoder { if(self = [super initWithCoder:aDecoder]) { self.delegate = self; self.dataSource = self; } return self; }
This will cause your delegate and data source methods to be called properly if you of course want the data source and delegates to be PageViewController. Once this is configured, you will need to make sure that when viewing the view there is a view controller. You can do this with the setViewControllers method in the PageViewController class in your DidLoad view:
- (void)viewDidLoad { [super viewDidLoad]; [self setViewControllers:@[sweetViewController] direction:UIPageViewControllerNavigationDirectionForward animated:YES completion:^(BOOL finished) { NSLog(@"Hooray I set my initial viewcontroller for my page view controller"); }]; }
When the PageViewController is created, it will start with your sweetViewController, and then, if necessary, start calling your data source and delegate methods.
source share