I am making simple intro screen. the screen slides on swipe but I want also swipe the intro screens with button tap but when I tap next button it shows an error.
complete code
#import <UIKit/UIKit.h>
#import "WalkthroughPageViewController.h"
#interface WalkthroughContentViewController : UIViewController
#property (weak, nonatomic) IBOutlet UILabel *pageLbl;
#property (weak, nonatomic) IBOutlet UIButton *nextBtn;
#property(strong,nonatomic)WalkthroughPageViewController *pageVC;
#property NSUInteger index;
#property NSString *heading;
#end
WalkthroughContentViewController.m
#import "WalkthroughContentViewController.h"
#interface WalkthroughContentViewController ()
#end
#implementation WalkthroughContentViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.pageLbl.text = self.heading;
switch (self.index) {
case 0:
case 1:
[self.nextBtn setTitle:#"Next" forState:UIControlStateNormal];
break;
case 2:
[self.nextBtn setTitle:#"Done" forState:UIControlStateNormal];
break;
default:
break;
}
}
- (IBAction)nextBtn:(id)sender {
switch (self.index) {
case 0:
case 1:
self.pageVC = ((WalkthroughPageViewController*)self.parentViewController);
[self.pageVC forward:self.index];
break;
case 2:
[self performSegueWithIdentifier:#"LoginScreen" sender:nil];
break;
default:
break;
}
}
#end
WalkthroughPageViewController.h
#import <UIKit/UIKit.h>
#interface WalkthroughPageViewController :UIPageViewController<UIPageViewControllerDataSource>
#property (strong, nonatomic) UIPageViewController *pageViewController;
#property NSArray *pageHeading;
-(void)forward:(NSUInteger)index;
#end
WalkthroughPageViewController.m
#import "WalkthroughPageViewController.h"
#import "WalkthroughContentViewController.h"
#interface WalkthroughPageViewController ()
#end
#implementation WalkthroughPageViewController
NSUInteger indexP;
- (void)viewDidLoad {
[super viewDidLoad];
self.pageHeading = #[#"page1",#"page2",#"page3"];
self.pageViewController = [[UIPageViewController alloc] init];
self.pageViewController.dataSource = self;
WalkthroughContentViewController *startingViewController = [self viewControllerAtIndex:0];
NSArray *viewControllers = #[startingViewController];
[_pageViewController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];
[self addChildViewController:self.pageViewController];
[self.view addSubview:self.pageViewController.view];
[self.pageViewController didMoveToParentViewController:self];
}
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController
{
indexP = ((WalkthroughContentViewController*) viewController).index;
if ((indexP == 0) || (indexP == NSNotFound)) {
return nil;
}
indexP--;
return [self viewControllerAtIndex:indexP];
}
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController
{
indexP = ((WalkthroughContentViewController*) viewController).index;
if (indexP == NSNotFound) {
return nil;
}
indexP++;
if (indexP == [self.pageHeading count]) {
return nil;
}
return [self viewControllerAtIndex:indexP];
}
- (WalkthroughContentViewController *)viewControllerAtIndex:(NSUInteger)index
{
if ((index == NSNotFound) || (index >= [self.pageHeading count])) {
return nil;
}
// Create a new view controller and pass suitable data.
WalkthroughContentViewController *pageContentViewController = [self.storyboard instantiateViewControllerWithIdentifier:#"WalkthroughContentViewController"];
pageContentViewController.heading = self.pageHeading[index];
pageContentViewController.index = index;
return pageContentViewController;
}
- (NSInteger)presentationCountForPageViewController:(UIPageViewController *)pageViewController
{
return [self.pageHeading count];
}
- (NSInteger)presentationIndexForPageViewController:(UIPageViewController *)pageViewController
{
return 0;
}
-(void)forward:(NSUInteger)index{
[self.pageViewController setViewControllers:#[[self viewControllerAtIndex:index]] direction:UIPageViewControllerNavigationDirectionForward animated:YES completion:nil];
}
#end
**Error:: **
[UIPageViewController forward:]: unrecognized selector sent to instance
Related
I want to put some static content (buttons, views etc) on UIPageViewController. But I don't know how.
Any ideas?
Just create a container uiviewcontroller that will have e.g. a static button and an empty uiview. Create them as iboutlets and a usual property UIPageViewController called pvc. Then you can create a pvc in code and add it to the uiview outlet via addSubview:.
This is some code copied from a project i did last weeek. There are Skidata in a UIPageViewController and put an UIImage of a snowflake as overlay about it. I copied only the relevant parts of code. Hope this will help you:
SkiViewController.m
#interface SkiViewController () <UIPageViewControllerDataSource>
#property (strong, nonatomic) UIPageViewController *pageController;
#property (strong, nonatomic) SkiDataArray* skiDataArray;
#property (weak, nonatomic) IBOutlet UIImageView *imageView;
#property (weak, nonatomic) IBOutlet UIView *pageDataView;
#end
#implementation SkiViewController
- (SkiSubViewController *)viewControllerAtIndex:(NSUInteger)index
{
SkiSubViewController *childViewController = [[SkiSubViewController alloc] initWithNibName:#"SkiSubViewController" bundle:nil];
childViewController.indexNumber = index;
if(self.skiDataArray)
{
childViewController.skiData = self.skiDataArray[index];
}
return childViewController;
}
#pragma mark - lify cycle
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
self.pageController = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:nil];
self.pageController.dataSource = self;
[self addPageControllerViewControllers];
[self addPageControllerView];
[self addChildViewController:self.pageController];
[self.pageController didMoveToParentViewController:self];
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self updateData]; // download ski data and stuff
}
- (void)addPageControllerViewControllers
{
SkiSubViewController *viewController = [self viewControllerAtIndex:0];
if(self.skiDataArray)
{
viewController.skiData = self.skiDataArray[0];
}
[self.pageController setViewControllers:#[viewController] direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];
}
- (void)addPageControllerView
{
self.pageController.view.translatesAutoresizingMaskIntoConstraints = NO; // avoids conflicts with auto generated constraints
[self.pageDataView addSubview:self.pageController.view];
NSDictionary *views = #{ #"subview": self.pageController.view };
[self.pageDataView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:#"H:|[subview]|" options:0 metrics: 0 views:views]];
[self.pageDataView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:#"V:|[subview]|" options:0 metrics: 0 views:views]];
[self.pageDataView updateConstraintsIfNeeded];
}
#pragma mark - uipageviewcontroller data source
- (UIViewController*)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController
{
NSUInteger index = [(SkiSubViewController *)viewController indexNumber];
if (index == 0)
{
return nil;
}
else
{
index--;
return [self viewControllerAtIndex:index];
}
}
- (UIViewController*)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController
{
NSUInteger index = ((SkiSubViewController *)viewController).indexNumber;
index++;
if (index == self.skiDataArray.count)
{
return nil;
}
else
{
return [self viewControllerAtIndex:index];
}
}
- (NSInteger)presentationCountForPageViewController:(UIPageViewController *)pageViewController
{
return self.skiDataArray.count;
}
- (NSInteger)presentationIndexForPageViewController:(UIPageViewController *)pageViewController
{
return 0;
}
#end
SkiSubViewController.h
#interface SkiSubViewController : UIViewController <UITableViewDataSource, UITableViewDelegate>
#property (assign, nonatomic) NSInteger indexNumber;
#property (strong, nonatomic) SkiData* skiData;
#end
SkiSubViewController.m
#interface SkiSubViewController ()
#property (weak, nonatomic) IBOutlet UILabel *label;
#end
#implementation SkiSubViewController
- (void)viewDidLoad
{
[super viewDidLoad];
self.label.text = [NSString stringWithFormat:#"Number %li", (long)self.indexNumber];
}
#end
Basically, I am making a page app, which use UIPageViewController. When the user scrolls the page, they can see different content. The problem now is, when I scroll the page, the first and second page works properly, and the index is correct. But when I scroll to the third page, the index keeps at "1", and don't change afterwards. And the other page keeps the appearance of the second page, whose index is "1".
I was following the tutorial: http://www.appcoda.com/uipageviewcontroller-storyboard-tutorial/
My code:
View Controller.h
#import <UIKit/UIKit.h>
#import "PageContentViewController.h"
#import "PageViewController.h"
#interface ViewController : UIViewController<UIPageViewControllerDataSource, UIPageViewControllerDelegate>
#property (strong, nonatomic) PageViewController *pageViewController;
#property (strong, nonatomic) NSArray *pageTitles;
#end
View Controller.m:
#import "ViewController.h"
#interface ViewController ()
#end
#implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.pageTitles = #[#"First Page", #"Second Page", #"Third Page"];
self.pageViewController = [self.storyboard instantiateViewControllerWithIdentifier:#"PageViewController"];
self.pageViewController.dataSource = self;
if ([self.pageTitles count])
{
PageContentViewController *startingViewController = [self viewControllerAtIndex: 0];
NSArray *viewControllers = #[startingViewController];
[self.pageViewController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];
self.pageViewController.view.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
[self addChildViewController:self.pageViewController];
[self.view addSubview:self.pageViewController.view];
[self.pageViewController didMoveToParentViewController:self];
}
}
- (PageContentViewController *) viewControllerAtIndex: (NSUInteger)index{
if (index < [self.pageTitles count])
{
PageContentViewController *pageContentViewController = [self.storyboard instantiateViewControllerWithIdentifier:#"PageContentViewController"];
pageContentViewController.titleText = self.pageTitles[index];
NSLog(#"%li", index);
UIColor *backgroundColor;
switch (index) {
case 0:
backgroundColor = [UIColor greenColor];
break;
case 1:
backgroundColor = [UIColor blueColor];
break;
case 2:
backgroundColor = [UIColor purpleColor];
break;
default:
break;
}
pageContentViewController.backgroundColor = backgroundColor;
return pageContentViewController;
}
return nil;
}
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController
{
NSUInteger index = ((PageContentViewController *)viewController).pageIndex;
if (index == NSNotFound)
{
return nil;
}
index++;
if (index == [self.pageTitles count])
{
return nil;
}
return [self viewControllerAtIndex:index];
}
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController
{
NSUInteger index = ((PageContentViewController *)viewController).pageIndex;
if (index == 0 || index == NSNotFound)
{
return nil;
}
index--;
return [self viewControllerAtIndex:index];
}
- (NSInteger) presentationCountForPageViewController:(UIPageViewController *)pageViewController
{
return [self.pageTitles count];
}
- (NSInteger) presentationIndexForPageViewController:(UIPageViewController *)pageViewController
{
return 0;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
Page Content View Controller.h
#import <UIKit/UIKit.h>
#interface PageContentViewController : UIViewController
#property (weak, nonatomic) IBOutlet UIView *backgroundView;
#property (weak, nonatomic) IBOutlet UILabel *titleLable;
#property (nonatomic) NSUInteger pageIndex;
#property (strong, nonatomic) NSString *titleText;
#property (strong, nonatomic) UIColor *backgroundColor;
#end
Page Content View Controller.m
#import "PageContentViewController.h"
#interface PageContentViewController ()
#end
#implementation PageContentViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.titleLable.text = self.titleText;
[self.backgroundView setBackgroundColor:self.backgroundColor];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/*
#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
In viewControllerAtIndex:, you need to set the value of pageIndex property of the pageContentViewController:
pageContentViewController.pageIndex = index;
I'm following this tutorial to create a UIPageViewController:
appcoda UIPageViewController tutorial
However, the only difference in the code is I am using only 1 UIViewController and 1 UIPageViewController instead of 2 UIViewControllers and 1 UIPageViewController, and I've modified the code to allow me to accomplish this.
However, Xcode seems to crash in viewDidLoad in the code:
[self.view addSubview:_pageViewController.view];
Here is my code:
.h
#property (strong, nonatomic) UIPageViewController *pageViewController;
#property (strong, nonatomic) NSArray *pageImages;
#property (nonatomic) NSUInteger pageIndex;
#property (nonatomic) NSString *titleText;
#property (strong, nonatomic) IBOutlet UIImageView *imageFile;
.m
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
// Override point for customization after application launch.
UIPageControl *pageControl = [UIPageControl appearance];
pageControl.pageIndicatorTintColor = [UIColor lightGrayColor];
pageControl.currentPageIndicatorTintColor = [UIColor blackColor];
pageControl.backgroundColor = [UIColor whiteColor];
self.pageImages = #[#"page1.png", #"page2.png", #"page3.png", #"page4.png"];
// Create page view controller
self.pageViewController = [self.storyboard instantiateViewControllerWithIdentifier:#"PageViewController"];
self.pageViewController.dataSource = self;
NSArray *viewControllers = #[ [self viewControllerAtIndex:0] ];
[self.pageViewController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];
// Change the size of page view controller
self.pageViewController.view.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height - 30);
// [self addChildViewController:_pageViewController];
[self.view addSubview:_pageViewController.view];
// [self.pageViewController didMoveToParentViewController:self];
}
- (id )viewControllerAtIndex:(NSUInteger)index
{
if ( ([self.pageImages count] == 0) || (index >= [self.pageImages count]) )
{
return nil;
}
self.imageFile = self.pageImages[index];
self.pageIndex = index;
return self;
}
#pragma mark - Page View Controller Data Source
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController
{
NSUInteger index = self.pageIndex;
if ((index == 0) || (index == NSNotFound)) {
return nil;
}
index--;
return [self viewControllerAtIndex:index];
}
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController
{
NSUInteger index = self.pageIndex;
if (index == NSNotFound)
{
return nil;
}
index++;
if (index == [self.pageImages count])
{
return nil;
}
return [self viewControllerAtIndex:index];
}
- (NSInteger)presentationCountForPageViewController:(UIPageViewController *)pageViewController
{
return [self.pageImages count];
}
- (NSInteger)presentationIndexForPageViewController:(UIPageViewController *)pageViewController
{
return 0;
}
I don't quite understand why it's crashing. Thanks for your help!
I have an app that presents a PageViewController tutorial scene. In my settings page I have a button that returns to the PageViewController, labeled IntroViewController.
When the tutorial first appears, it works fine. But when I go back, the dots at the base of the PageViewController disappear. Any idea why this happens?
Here is the IntroViewController.m
#import "IntroViewController.h"
#interface IntroViewController ()
#end
#implementation IntroViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Create the data model
_pageTitles = #[#"Over 200 Tips and Tricks", #"Discover Hidden Features", #"Bookmark Favorite Tip", #"Another one!"];
if ([[UIScreen mainScreen] bounds].size.height == 568) {
_pageImages = #[#"IntroExpand.png", #"IntroSlow.png", #"IntroImport.png", #"IntroRename.png"];
}
else {
_pageImages = #[#"IntroExpand.png", #"IntroSlow.png", #"IntroImport.png", #"IntroRename.png"];
}
// Create page view controller
self.pageViewController = [self.storyboard instantiateViewControllerWithIdentifier:#"PageViewController"];
self.pageViewController.dataSource = self;
PageContentViewController *startingViewController = [self viewControllerAtIndex:0];
NSArray *viewControllers = #[startingViewController];
[self.pageViewController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];
// Change the size of page view controller
self.pageViewController.view.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height - 5);
[self addChildViewController:_pageViewController];
[self.view addSubview:_pageViewController.view];
[self.pageViewController didMoveToParentViewController:self];
[self.view bringSubviewToFront:self.ready];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
- (IBAction)ready:(id)sender { //this is the action that the user does to dismiss the tutorial and go to the first scene
UIStoryboard *storyBoard;
storyBoard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
UIViewController *viewController =
[storyBoard instantiateViewControllerWithIdentifier:#"NavigationViewController"];
[self presentViewController:viewController animated:YES completion:nil];
}
#pragma mark - Page View Controller Data Source
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController
{
NSUInteger index = ((PageContentViewController*) viewController).pageIndex;
if ((index == 0) || (index == NSNotFound)) {
return nil;
}
index--;
return [self viewControllerAtIndex:index];
}
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController
{
NSUInteger index = ((PageContentViewController*) viewController).pageIndex;
if (index == NSNotFound) {
return nil;
}
index++;
if (index == [self.pageTitles count]) {
return nil;
}
return [self viewControllerAtIndex:index];
}
- (PageContentViewController *)viewControllerAtIndex:(NSUInteger)index
{
if (([self.pageTitles count] == 0) || (index >= [self.pageTitles count])) {
return nil;
}
// Create a new view controller and pass suitable data.
PageContentViewController *pageContentViewController = [self.storyboard instantiateViewControllerWithIdentifier:#"PageContentViewController"];
pageContentViewController.imageFiles = self.pageImages[index];
pageContentViewController.titleText = self.pageTitles[index];
pageContentViewController.pageIndex = index;
return pageContentViewController;
}
- (NSInteger)presentationCountForPageViewController:(UIPageViewController *)pageViewController
{
return [self.pageTitles count];
}
- (NSInteger)presentationIndexForPageViewController:(UIPageViewController *)pageViewController
{
return 0;
}
#end
Here is the IntroViewController.h
#import <UIKit/UIKit.h>
#import "PageContentViewController.h"
#interface IntroViewController : UIViewController <UIPageViewControllerDataSource>
- (IBAction)ready:(id)sender;
#property (weak, nonatomic) IBOutlet UIButton *ready;
#property (weak, nonatomic) UIPageViewController *pageViewController;
#property (strong, nonatomic) NSArray *pageTitles;
#property (strong, nonatomic) NSArray *pageImages;
#end
And here is the button/action that takes the user from the settings page to the tutorial. I've tried different segues, modal, push, etc., and they all have the same problem of not displaying the dots when the user returns to the tutorial
- (IBAction)tutorialReplay:(id)sender {
UIStoryboard *storyBoard;
storyBoard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
UIViewController *viewController =
[storyBoard instantiateViewControllerWithIdentifier:#"IntroViewController"];
[self presentViewController:viewController animated:YES completion:nil];
}
Let me know if I need to add more code to help. Thanks all.
I have three view controllers: Settings,Chatbox and QuickMsg.
I want to use UIPageViewController to switch between these three view controllers. For each view controller, I don't want to re-initiate the view controller between swiping pages since it contains user inputed data and I want to persist the data. I defined three view controllers as static variables.
The screen goes black when I swipe between pages. Where have I done wrong?
Thanks a lot in advance!
ChatboxController, SettingController and QuickMsgController are three UIViewController controllers.
PagingViewController.h
#import <UIKit/UIKit.h>
#import "ChatboxController.h"
#import "SettingController.h"
#import "PagingViewController.h"
#import "QuickMsgController.h"
#class ChatboxController;
#class SettingController;
#class QuickMsgController;
#interface PagingViewController : UIViewController<UIPageViewControllerDataSource>
#property (strong, nonatomic) UIPageViewController *pageController;
#property (assign, nonatomic) NSInteger index;
+(ChatboxController*) getChatboxController;
+(SettingController*) getSettingsController;
#end
PagingViewController.m
#import "PagingViewController.h"
#interface PagingViewController ()
#end
#implementation PagingViewController
static ChatboxController* chatboxViewController;
static SettingController* settingViewController;
static QuickMsgController* quickMessageViewController;
int defaultIndex=1;
NSArray *viewControllers;
+(ChatboxController*) getChatboxController
{
return chatboxViewController;
}
+(SettingController*) getSettingsController
{
return settingViewController;
}
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController {
self.index--;
if(self.index<0)
{
self.index=0;
}
return [self viewControllerAtIndex:self.index];
}
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController {
self.index++;
return [self viewControllerAtIndex:self.index];
}
- (UIViewController *)viewControllerAtIndex:(NSUInteger)index {
NSLog(#"index:%d",index);
if(index==1)
{
return chatboxViewController;
}
else if (index==0){
return settingViewController;
}else if(index==2)
{
NSLog(#"Quick Message");
return quickMessageViewController;
}else{
NSLog(#"error here");
return nil;
}
}
- (NSInteger)presentationCountForPageViewController:(UIPageViewController *)pageViewController {
// The number of items reflected in the page indicator.
return 3;
}
- (NSInteger)presentationIndexForPageViewController:(UIPageViewController *)pageViewController {
// The selected item reflected in the page indicator.
return defaultIndex;
}
- (void)viewDidLoad
{
[super viewDidLoad];
chatboxViewController= [self.storyboard instantiateViewControllerWithIdentifier:#"chatbox"];
settingViewController= [self.storyboard instantiateViewControllerWithIdentifier:#"settings"];
quickMessageViewController=[self.storyboard instantiateViewControllerWithIdentifier:#"quickmessages"];
self.index=defaultIndex;
// [self performSelector:#selector(loadingNextView) withObject:nil afterDelay:2.0f];
self.pageController = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:nil];
self.pageController.dataSource = self;
[[self.pageController view] setFrame:[[self view] bounds]];
NSArray *viewControllers = [NSArray arrayWithObject:chatboxViewController];
[self.pageController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];
[self addChildViewController:self.pageController];
[[self view] addSubview:[self.pageController view]];
[self.pageController didMoveToParentViewController:self];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
Put your content view controllers in an NSArray:
#property (nonatomic, strong) NSArray *contentViewControllers;
Use:
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController
viewControllerBeforeViewController:(UIViewController *)viewController {
NSUInteger index = [self.contentViewControllers indexOfObject:viewController];
if (index == 0) {
return nil;
}
return self.contentViewControllers[index - 1];
}
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController
viewControllerAfterViewController:(UIViewController *)viewController {
NSUInteger index = [self.contentViewControllers indexOfObject:viewController];
if (index >= self.contentViewControllers.count - 1) {
return nil;
}
return self.contentViewControllers[index + 1];
}
- (NSInteger)presentationCountForPageViewController:(UIPageViewController *)pageViewController {
return self.contentViewControllers.count;
}
- (NSInteger)presentationIndexForPageViewController:(UIPageViewController *)pageViewController {
return 0;
}