There are 15 viewcontrollers in my App.I want to swipe them horizontally.
I have added all these view controllers in uipageviewcontroller(I have written this code in my first viewcontroller). Each of the 15 viewcontrollers contains buttons to go to the remaining all viewcontrolers.so How could I jump to these viewcontrollers inside pageviewcontroller?,so that I can not come outside of horizontal swipe.
This is my code.Currently I have added three viewcontrollers in uipageviewcontroller.
This is what I have written in Appdelegate.
#interface AppDelegate : UIResponder <UIApplicationDelegate>
#property (strong, nonatomic) UIWindow *window;
#property (nonatomic, strong) UIPageViewController *pageViewController;
#property (nonatomic, strong) NSArray *contentViewControllers;
This is my viewcontroller.m (i.e. initial viewcontroller).
APP_DELEGATE.pageViewController = [self.storyboard instantiateViewControllerWithIdentifier:#"PageView"];
APP_DELEGATE.pageViewController.dataSource = self;
UIViewController *init = [self.storyboard instantiateViewControllerWithIdentifier:#"ViewController"];
FirstViewController *first = [self.storyboard instantiateViewControllerWithIdentifier:#"FirstViewController"];
secondViewController *second = [self.storyboard instantiateViewControllerWithIdentifier:#"secondViewController"];
thirdViewController *third = [self.storyboard instantiateViewControllerWithIdentifier:#"thirdViewController"];
APP_DELEGATE.contentViewControllers = [NSArray arrayWithObjects:init,first,second,third,first,nil];
[APP_DELEGATE.pageViewController setViewControllers:#[first] direction:UIPageViewControllerNavigationDirectionReverse animated:NO completion:nil];
[self addChildViewController:APP_DELEGATE.pageViewController];
[self.view addSubview:APP_DELEGATE.pageViewController.view];
[APP_DELEGATE.pageViewController didMoveToParentViewController:self];
self.view.backgroundColor = [UIColor colorWithRed:(248.0/255.0) green:(248.0/255.0) blue:(248.0/255.0) alpha:1.0];
}
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController
viewControllerBeforeViewController:(UIViewController *)viewController {
NSUInteger index = [APP_DELEGATE.contentViewControllers indexOfObject:viewController];
if (index == 1) {
return nil;
}
return APP_DELEGATE.contentViewControllers[index - 1];
}
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController
viewControllerAfterViewController:(UIViewController *)viewController {
NSUInteger index = [APP_DELEGATE.contentViewControllers indexOfObject:viewController];
if (index >= APP_DELEGATE.contentViewControllers.count - 1) {
return nil;
}
return APP_DELEGATE.contentViewControllers[index + 1];
}
This is my secondViewcontroller.m
- (IBAction)moveToFirstButtonAction:(id)sender {
FirstViewController *fvc = [APP_DELEGATE.contentViewControllers objectAtIndex:1];
fvc.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentViewController:fvc animated:YES completion:nil];
}
Using this method I jump to the firstViewcontroller. But I come out of horizontal swipe. i.e. horizontal swipe will not work then.
You can get the reference of viewcontrollers in array. Like this way:
PageViewController *pageView;
would be your page view.
#property (nonatomic, readonly) NSArray *viewControllers;
NSArray *viewControlers = pageView.viewControllers;
And thereafter you can go to any viewcontroller just passing the index of viewcontroller you want to go.
Thanks it helps.
Regards,
Harry
Related
I am following this link CustomPageControlForPageViewController to implement SwipeView menu. In this project, there are only two ViewControllers which involves in the swipe transition. But my requirement is of three ViewControllers like. So I am not getting any idea that, how to implement the UIPageViewController delegate methods with three ViewControllers which ll handle the transition from one view to other. Here is the code from the given link for two ViewControllers.
swipe.h
#interface RootViewController : UIViewController <UIPageViewControllerDataSource, UIPageViewControllerDelegate>
#property (strong, nonatomic) UIPageViewController *pageViewController;
#property (strong, nonatomic) UIView *pageControlCustomView;
#end
swipe.m
#interface RootViewController () {
NSArray *viewControllers;
UIView *selectionBar;
int SELECTOR_WIDTH;
int SELECTOR_Y;
UIButton *leftButton;
UIButton *rightButton;
moveSelectorBarLeftBlockType moveSelectorBarLeft;
moveSelectorBarRightBlockType moveSelectorBarRight;
UIViewController *firstVC;
UIViewController *secondVC;
}
#end
#implementation RootViewController
- (void)viewDidLoad {
[super viewDidLoad];
SELECTOR_WIDTH = self.view.frame.size.width/2;
SELECTOR_Y = self.navigationController.navigationBar.frame.size.height + Y_OFFSET_BELOW_NAVBAR + HEIGHT;
UIPageControl *pageControl = [UIPageControl appearance];
pageControl.pageIndicatorTintColor = [UIColor blackColor];
// Create page view controller
self.pageViewController = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:nil];
self.pageViewController.dataSource = self;
self.pageViewController.delegate = self;
firstVC = [self.storyboard instantiateViewControllerWithIdentifier:#"firstViewController"];
secondVC = [self.storyboard instantiateViewControllerWithIdentifier:#"secondViewController"];
viewControllers = #[firstVC];
[self.pageViewController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];
}
#pragma mark - Page View Controller Data Source
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController
{
if (self.pageViewController.viewControllers[0] == secondVC)
return firstVC;
return nil;
}
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController
{
if (self.pageViewController.viewControllers[0] == firstVC)
return secondVC;
return nil;
}
- (void)pageViewController:(UIPageViewController *)pageViewController didFinishAnimating:(BOOL)finished previousViewControllers:(NSArray *)previousViewControllers transitionCompleted:(BOOL)completed {
if (completed) {
if (previousViewControllers[0] == secondVC) {
moveSelectorBarLeft();
}
else {
moveSelectorBarRight();
}
}
}
I recommend you to use your own array to store the order of your viewControllers.
Here is how I work with this delegate
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController {
NSUInteger index = [self.viewControllers indexOfObject:viewController];
if (index == 0) { return nil;}
index--;
UIViewController *targetViewController = [self.viewControllers objectAtIndex:index];
return targetViewController;
}
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController {
NSUInteger index = [self.viewControllers indexOfObject:viewController];
index++;
if (index >= self.viewControllers.count) { return nil;}
UIViewController *targetViewController = [self.viewControllers objectAtIndex:index];
return targetViewController;
}
I have 2 view controllers. viewController1 has a UILabel called nameLabel which I want to set in a different class, viewController2.
I try calling this code from viewController2.
Content1ViewController *viewController1 = [Content1ViewController new];
viewController1.nameLabel.text = #"HELLO";
NSLog(#"%#",viewController1.nameLabel);
However, the viewController1 nameLabel doesn't change when I call the code? Also the NSLog returns "null"?? Can someone tell me why this is happening and also how I can change the nameLabel from a different class? Thanks!
Controls are not initialized when you manually create the instance. This is done on a later stage of view controller life cycle.
If I'm not mistaken, first event where you will see controls initialized is viewDidLoad
Something you can do is adding a NSString property named (let's say) nameLabelText and do nameLabel.text = nameLabelText; on viewDidLoad
You need to take the same instance of viewController which was on the window. If you are pushing viewController2 into navigation controller stack then get instance of viewController1 from navigation stack and then try to set the label.
If you are using present modal then use presentingViewController instance of viewController2 in order to access instance of viewController1 like
viewController1 *controller = [viewController2 presentingViewController];
[controller.nameLabel setText:#"WhatEver"];
Where have you set the property for namelabel?
Did you use Interface Builder (XIB or Storyboard) or have you done it all in code?
If the you did it in InterfaceBuilder than
[Content1ViewController new]
is the wrong approach.
For XIB-Files you should use
initWithNibName:(NSString *)nibName
bundle:(NSBundle *)nibBundle
and if your ViewController has been defined in a storyboard you should use
instantiateViewControllerWithIdentifier:(NSString *)identifier
from UIStoryboard.
But as Claudio Redi already said the earliest point where you will be able to access the UILabel will be in viewDidLoad
If everything in code, you should put
[self setNameLabel:[[UILabel alloc] initWithFrame:CGRectMake(50.0f,50.0f,100.0f,100.0f)];
in the init-Method of your ViewController.
//
// ViewController.m
// UIPageViewControllerDemo
//
// Created by YunYi1118 on 15/5/20.
// Copyright (c) 2015年 Xiaoyi. All rights reserved.
//
#import "ViewController.h"
#import "MoreViewController.h"
#interface ViewController () <UIPageViewControllerDataSource, UIPageViewControllerDelegate>
#property (strong, nonatomic) UIPageViewController *pageController;
#property (strong, nonatomic) NSArray *pageContent;
#end
#implementation ViewController
#synthesize pageContent = _pageContent;
#synthesize pageController = _pageController;
- (void)viewDidLoad {
[super viewDidLoad];
[self createContentPages];
NSDictionary *options = [NSDictionary dictionaryWithObject:[NSNumber numberWithInteger:UIPageViewControllerSpineLocationMin] forKey:UIPageViewControllerOptionSpineLocationKey];
self.pageController = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStylePageCurl navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:options];
_pageController.dataSource = self;
_pageController.view.frame = self.view.bounds;
MoreViewController *initialViewController = [self viewControllerAtIndex:0];
NSArray *viewControllers = [NSArray arrayWithObject:initialViewController];
[self.pageController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];
[self addChildViewController:_pageController];
[self.view addSubview:_pageController.view];
}
- (MoreViewController *)viewControllerAtIndex:(NSUInteger)index
{
if (self.pageContent.count == 0 || index >= self.pageContent.count) {
return nil;
}
MoreViewController *dataViewController = [[MoreViewController alloc] init];
dataViewController.dataObject = [self.pageContent objectAtIndex:index];
return dataViewController;
}
- (void)createContentPages
{
NSMutableArray *pageStrings = [NSMutableArray array];
for (int i = 1; i < 11; i++) {
NSString *contentString = [[NSString alloc] initWithFormat:#"Chapter%d, This is the page %d of content displayed using UIPageViewController ",i,i];
[pageStrings addObject:contentString];
}
self.pageContent = [NSArray arrayWithArray:pageStrings];
}
#pragma mark - delegate
- (NSUInteger)indexOfViewController:(MoreViewController *)viewController
{
return [self.pageContent indexOfObject:viewController.dataObject];
}
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController
{
NSUInteger index = [self indexOfViewController:(MoreViewController *)viewController];
if (index == 0 || index == NSNotFound) {
return nil;
}
index--;
return [self viewControllerAtIndex:index];
}
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController
{
NSUInteger index = [self indexOfViewController:(MoreViewController *)viewController];
if (index == NSNotFound) {
return nil;
}
index++;
if (index == self.pageContent.count) {
return nil;
}
return [self viewControllerAtIndex:index];
}
#end
I'm trying to add UIPageViewController to my RootViewController in code. I removed storyboard file according to
Xcode 5 without Storyboard and ARC
and adding “regular” ViewController works perfectly. I adoped methods according to UIPageViewControllerDataSource
Also I tried to simplify logic (instead of implementing ModelController from starting PageView project I add showVCWithIndex: method to pick 1 of 3 VC from vcArray and write it to Mutable Array with 1 VC. Hope you can tell me if I was right or wrong about that.
.m
#import "RootPageViewController.h"
#import "ViewController0.h"
#import "ViewController1.h"
#import "ViewController2.h"
#interface RootPageViewController ()
#property (strong, nonatomic) ViewController0 *vController0;
#property (strong, nonatomic) ViewController1 *vController1;
#property (strong, nonatomic) ViewController2 *vController2;
#property (strong, nonatomic) UIPageViewController *pageViewController;
#property (strong, nonatomic) NSArray *vcArray;
#property (strong, nonatomic) NSMutableArray *viewController;
#end
#implementation RootPageViewController
- (void)viewDidLoad
{
[super viewDidLoad];
self.pageViewController = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:nil];
self.pageViewController.dataSource = self;
_vController0 = [[ViewController0 alloc] init];
_vController1 = [[ViewController1 alloc] init];
_vController2 = [[ViewController2 alloc] init];
NSUInteger index = 0;
NSMutableArray *viewController = [NSMutableArray arrayWithObjects:[self showVCWithIndex:index], nil];
[self.pageViewController setViewControllers:viewController
direction:UIPageViewControllerNavigationDirectionForward
animated:NO
completion:nil];
[self addChildViewController:self.pageViewController];
[self.view addSubview:self.pageViewController.view];
CGRect pageViewRect = self.view.bounds;
self.pageViewController.view.frame = pageViewRect;
[self.pageViewController didMoveToParentViewController:self];
}
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController
viewControllerBeforeViewController:(UIViewController *)viewController
{
NSUInteger index = [self.vcArray indexOfObject:viewController];
if ((index == 0) || (index == NSNotFound)) {
return nil;
}
index--;
return [self showVCWithIndex:index];
}
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController
viewControllerAfterViewController:(UIViewController *)viewController
{
NSUInteger index = [self.vcArray indexOfObject:viewController];
if (index == 2 || index == NSNotFound) {
return nil;
}
index++;
return [self showVCWithIndex:index];
}
- (UIViewController *)showVCWithIndex: (NSUInteger)index
{
self.vcArray = [NSArray arrayWithObjects: _vController0, _vController1, _vController2, nil];
UIViewController *currentVC = [self.vcArray objectAtIndex:index];
return currentVC;
}
#end
EDIT
got the solution (this code works, but I'm not sure if I am 100% right)
When you call...
[self.pageViewController setViewControllers:[vcArray objectAtIndex:0]
direction:UIPageViewControllerNavigationDirectionForward
animated:NO
completion:nil];
... you are setting a nil view controller to the pagination view controller.
[vcArray objectAtIndex:0] points to _vController0 which is, in that moment, nil (you haven't instantiated it yet).
Before set you view controllers into the pagination, you must get it from the storyboard using [self.storyboard instatiateViewControllerWithIdentifier:#"YourViewControllerIdentifier"] or simply calling a alloc init, if you are using Xibs.
When you set the view controllers in your UIPageViewController it has to be an array with only one view controller. The method -setViewControllers:direction:animated:completion: is so misleading. I had the same problem as you when I created a page view controller for the first time.
To allow your page view controller to display other view controllers you return them in the UIPageViewControllerDataSource methods -pageViewController:viewControllerBeforeViewController: and -pageViewController:viewControllerAfterViewController:.
So i need to create a UIPageViewController that shows a few views (1-25). Basically i have a quiz app, and for every wrong question i save the question number (1-25) in a NSMutableArray. After the quiz is done i want to show the user which quiz answer was wrong. I have the methods that sets the view of the wrong answers (same methods i use to set the views in the quiz).
This keeps giving me 'Thread1:' errors.
PVCPagesViewController.h
#import <UIKit/UIKit.h>
#import "PVCContentViewController.h"
#interface PVCPagesViewController : UIViewController <UIPageViewControllerDataSource, UIPageViewControllerDelegate>
#property (weak, nonatomic) IBOutlet UIPageControl *pageControl;
#end
.
PVCPagesViewController.m
#import "PVCPagesViewController.h"
#interface PVCPagesViewController () {
NSArray *pages;
}
#property (retain, nonatomic) NSArray *pages;
#property (strong, nonatomic) UIPageViewController *pageController;
#end
#implementation PVCPagesViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
//I think my problem is around here?
PVCContentViewController *page1 = [[PVCContentViewController alloc] init];
[page1 example1];
PVCContentViewController *page2 = [[PVCContentViewController alloc] init];
[page1 example2];
PVCContentViewController *page3 = [[PVCContentViewController alloc] init];
[page1 example3];
PVCContentViewController *page4 = [[PVCContentViewController alloc] init];
[page1 example2];
// load the view controllers in our pages array
self.pages = [[NSArray alloc] initWithObjects:page1, page2, page3, page4, nil];
self.pageController = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:nil];
[self.pageController setDelegate:self];
[self.pageController setDataSource:self];
[[self.pageController view] setFrame:[[self view] bounds]];
NSArray *viewControllers = [NSArray arrayWithObject:[self.pages objectAtIndex:0]];
[self.pageControl setCurrentPage:0];
[self.pageControl addTarget:self action:#selector(changePage:) forControlEvents:UIControlEventValueChanged];
[self.pageController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];
[self addChildViewController:self.pageController];
[self.view addSubview:self.pageControl];
[[self view] addSubview:[self.pageController view]];
[self.pageController didMoveToParentViewController:self];
[self.view sendSubviewToBack:[self.pageController view]];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController {
NSUInteger currentIndex = [self.pages indexOfObject:viewController]; // get the index of the current view controller on display
[self.pageControl setCurrentPage:self.pageControl.currentPage+1]; // move the pageControl indicator to the next page
// check if we are at the end and decide if we need to present the next viewcontroller
if ( currentIndex < [self.pages count]-1) {
return [self.pages objectAtIndex:currentIndex+1]; // return the next view controller
} else {
return nil; // do nothing
}
}
- (UIViewController *) pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController {
NSUInteger currentIndex = [self.pages indexOfObject:viewController]; // get the index of the current view controller on display
[self.pageControl setCurrentPage:self.pageControl.currentPage-1]; // move the pageControl indicator to the next page
// check if we are at the beginning and decide if we need to present the previous viewcontroller
if ( currentIndex > 0) {
return [self.pages objectAtIndex:currentIndex-1]; // return the previous viewcontroller
} else {
return nil; // do nothing
}
}
- (void)changePage:(id)sender {
UIViewController *visibleViewController = self.pageController.viewControllers[0];
NSUInteger currentIndex = [self.pages indexOfObject:visibleViewController];
NSArray *viewControllers = [NSArray arrayWithObject:[self.pages objectAtIndex:self.pageControl.currentPage]];
if (self.pageControl.currentPage > currentIndex) {
[self.pageController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];
} else {
[self.pageController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionReverse animated:NO completion:nil];
}
}
#end
.
PVCContentViewController.h
#import <UIKit/UIKit.h>
#import "PVCPagesViewController.h"
#interface PVCContentViewController : UIPageViewController
#property (weak, nonatomic) IBOutlet UILabel *label1;
#property (weak, nonatomic) IBOutlet UILabel *label2;
#property (weak, nonatomic) IBOutlet UILabel *label3;
-(void)example1;
-(void)example2;
-(void)example3;
#end
And lastly:
PVCContentViewController.m
#import "PVCContentViewController.h"
#interface PVCContentViewController ()
#end
#implementation PVCContentViewController
#synthesize label3,label2,label1;
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- (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.
}
*/
-(void)example1{
label1.text = #"View 1";
label2.text = #"View 1";
label3.text = #"view 1";
}
-(void)example2{
label1.text = #"View 2";
label2.text = #"View 2";
label3.text = #"view 2";
}
-(void)example3{
label1.text = #"View 3";
label2.text = #"View 3";
label3.text = #"view 3";
}
#end
I have borrowed the start source code from here:
https://github.com/hackin247/UIPageViewController
My source code:
https://github.com/4FunAndProfit/UIPageViewControllerHelp
Please let me know if you need anymore info!
Have you tried setting the pageController with the self.pages array directly?
[self.pageController setViewControllers:pages direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];
I don't see the point of creating yet another array(viewControllers). Maybe this is causing issues when trying to get the next page since the pageController only has a single viewController ([self.pages objectAtIndex:0]) but the "data source" says it should have more based on the self.pages.count.
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.