so I'm pretty new to Obj-C and have tried looking at sample code and other online resources to answer my question, but I can't seem to find anything that really helps. Essentially what I'm trying to do is to add multiple UIViewControllers that I created in Storyboard to a UIPageViewController - the first place I looked to for help was Xcode itself by using a template of a PageBased application. That actually helped quite a lot and I got a PageController up and running. Then I turned to online resources but most (if not all of them) use a single viewController (like this). Then I turned to StackOverflow and found the following - How to implement UIPageViewController that utilizes multiple ViewControllers. The above resources got me this far: In PageViewController.h:
#import <UIKit/UIKit.h>
@interface PageViewController : UIPageViewController <UIPageViewControllerDataSource>
@end
In PageViewController.m:
#import "PageViewController.h"
@interface PageViewController ()
@end
@implementation PageViewController {
NSArray *viewControllers;
UIViewController *first;
UIViewController *second;
UIViewController *third;
UIViewController *fourth;
UIViewController *fifth;
}
- (UIViewController *)first {
UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Secondary" bundle:nil];
first = [sb instantiateViewControllerWithIdentifier:@"1"];
return first;
}
- (UIViewController *)second {
UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Secondary" bundle:nil];
second = [sb instantiateViewControllerWithIdentifier:@"2"];
return second;
}
- (UIViewController *)third {
UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Secondary" bundle:nil];
third = [sb instantiateViewControllerWithIdentifier:@"3"];
return third;
}
- (UIViewController *)fourth {
UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Secondary" bundle:nil];
fourth = [sb instantiateViewControllerWithIdentifier:@"4"];
return fourth;
}
- (UIViewController *)fifth {
UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Secondary" bundle:nil];
fifth = [sb instantiateViewControllerWithIdentifier:@"5"];
return fifth;
}
- (void)viewDidLoad {
[super viewDidLoad];
self.dataSource = self;
// Aggancio il view controller iniziale.
[self setViewControllers:@[self.first]
direction:UIPageViewControllerNavigationDirectionForward
animated:YES
completion:nil];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController {
UIViewController *nextViewController = nil;
if (viewController == self.first) {
nextViewController = self.second;
}
if (viewController == self.second) {
nextViewController = self.third;
}
if (viewController == self.third) {
nextViewController = self.fourth;
}
if (viewController == fourth) {
nextViewController = self.fifth;
}
return nextViewController;
}
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController {
UIViewController *prevViewController = nil;
if (viewController == self.fifth) {
prevViewController = self.fourth;
}
if (viewController == self.fourth) {
prevViewController = self.third;
}
if (viewController == self.third) {
prevViewController = self.second;
}
if (viewController == self.second) {
prevViewController = self.first;
}
return prevViewController;
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
@end
All this code does is load the first view controller which is now swipe-able, but doesn't actually swipe towards anything - why is this?. What am I doing wrong? The aforementioned resources used titles and pages to create views and I really don't know how to go about this. Would anyone mind guiding me or nudging me in the correct direction? Any help would be greatly appreciated. Thanks!