How to create swipe navigation in iOS (in Objective-C) - ios

I want to build swipe navigation like the one shown in these pics. There are total 4 headings placed horizontally.
swipe navigation
They are as follows.
"History"
"Rules"
"PRO"
"Terms And Conditions"
If i am reading "History" & swipe from right to left, then the "Rules" should be displayed.
And if am on "Rules", and swipe from left to right then it should display "History"
Can anyone please guide me how to do this ?
Thanks.

The link you posted is a static screenshot, and not very helpful in describing what you want to do.
I think what you are describing is a normal behavior for a UIPageViewController, set up for a slide transition rather than a page curl transition.
Do a search on "PhotoScroller" in Xcode. That will point to a demo app that illustrates the effect I think you are after. That app is more complex than you need as it supports pinch zooming and tiled rendering of pictures, but you can ignore that stuff.

I too would recommend a UIPageViewController. Here is a bare bones implementation:
#interface SwipeViewController : UIViewController <UIPageViewControllerDataSource>
#property (nonatomic, strong) UIPageViewController *pageViewController;
#property (nonatomic, strong) NSArray <UIViewController*> *viewControllers;
#end
#implementation SwipeViewController
- (void)viewDidLoad {
[super viewDidLoad];
// add page view controller
[self.pageViewController willMoveToParentViewController:self];
[self.view addSubview:self.pageViewController.view];
[self addChildViewController:self.pageViewController];
[self.pageViewController didMoveToParentViewController:self];
// set the first view controller as the displayed view controllers (requires an array of exactly one view controller)
[self.pageViewController setViewControllers:#[self.viewControllers.firstObject] direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];
}
// array of 4 random colored view controllers
- (NSArray <UIViewController*>*)viewControllers {
if (!_viewControllers) {
_viewControllers = ({
NSMutableArray *viewControllers = [NSMutableArray new];
for (int i = 0; i < 4; i++) {
UIViewController *aViewController = [UIViewController new];
aViewController.view.backgroundColor = [UIColor colorWithRed:(arc4random()%255)/255. green:(arc4random()%255)/255. blue:(arc4random()%255)/255. alpha:1];
[viewControllers addObject:aViewController];
}
viewControllers;
});
}
return _viewControllers;
}
- (UIPageViewController *)pageViewController {
if (!_pageViewController) {
_pageViewController = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:nil];
_pageViewController.dataSource = self;
}
return _pageViewController;
}
- (nullable UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController {
NSInteger index = [self.viewControllers indexOfObject:viewController];
return index > 0 ? self.viewControllers[index-1] : nil;
}
- (nullable UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController {
NSInteger index = [self.viewControllers indexOfObject:viewController];
return index + 1 < self.viewControllers.count ? self.viewControllers[index+1] : nil;
}
#end

Related

UIPageViewController Child's viewWillAppear: & viewDidAppear: transition calls

How does one ensure that the viewWillAppear: and viewDidAppear: (and other view transition methods) are called on a UIPageViewController's child ViewControllers?
In my case, the view transition methods are adequately called on all except for the very firstViewController that the UIPageViewController opens to. On that firstViewController, the viewDidAppear: and viewWillAppear: methods are actually called BEFORE the UIPageViewController's view transition methods. And then as one starts scrolling, the viewWillAppear: and viewDidAppear: methods are called as one would expect for the new view controllers.
Here is my structure: I have a BossViewController that contains an OrganizerViewController (a couple different organizers, actually, but that is irrelevant). The OrganizerViewController contains a UIPageViewController, which contains a series of CustomViewControllers. My code adequately calls the child view transition methods as per apple (https://developer.apple.com/library/ios/featuredarticles/ViewControllerPGforiPhoneOS/ImplementingaContainerViewController.html) for the interactions between the BossViewController and the OrganizerViewController (fully functional, perfectly so). The problem lies somewhere between the OrganizerViewController, it's child UIPageViewController, and it's first child CustomPageViewController.
I have tried calling beginAppearanceTransition: and endAppearanceTransition: within the UIPageViewController's viewWillAppear: and viewDidAppear: - but that resulted in an 'unbalanced calls' error log to console.
Here is the UIPageViewController set up code, all of which is in the OrganizerViewController:
- (void)configurePVC
{
NSDictionary *key = #{UIPageViewControllerOptionInterPageSpacingKey : #([UIScreen mainScreen].bounds.size.width * 0.5)};
_pvc = [[AVSCustomPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll
navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:key];
self.pvc.delegate = self;
self.pvc.dataSource = self;
_pvcArray = [[NSMutableArray alloc] init];
CustomViewController *daily = (CustomViewController *)[self viewControllerAtIndex:6];
self.index = 6;
[self.pvcArray addObject:daily];
[self.pvc setViewControllers:self.pvcArray
direction:UIPageViewControllerNavigationDirectionForward
animated:YES
completion:nil];
[self addChildViewController:self.pvc];
[self.dailyContainerView addSubview:self.pvc.view];
self.pvc.view.frame = self.dailyContainerView.bounds;
[self.pvc didMoveToParentViewController:self];
}
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController
{
NSUInteger index = [(CustomViewController *)viewController index];
if (index == 0) {
return nil;
}
index--;
return [self viewControllerAtIndex:index];
}
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController {
NSUInteger index = [(CustomViewController *)viewController index];
if (index == 6) {
return nil;
}
index++;
return [self viewControllerAtIndex:index];
}
- (UIViewController *)viewControllerAtIndex:(NSUInteger)index
{
CustomViewController *viewController = [[CustomViewController alloc] init];
viewController.index = index;
return viewController;
}

UIPageViewController viewControllerAfterViewController never called

I have a UIPageViewController that I've set up with an array as the datasource. I see the first page fine and the presentation count dots show up correctly, but when I try to drag the to the next page nothing happens. So I set up some breakpoints in the viewControllerAfterViewController as well as Before methods and they never get called on. The other dataSource methods for presentationCountForPageViewController get called on fine.
Any idea what I am missing? I've been going line by line with examples I've found on the web but can't find anything.
- (void)viewDidLoad
{
[super viewDidLoad];
UIPageViewController *pageController = self.pageController;
pageController.dataSource = self;
UIChildViewController *initialViewController = [self viewControllerAtIndex:0];
NSArray *viewControllers = #[initialViewController];
[pageController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:YES completion:nil];
[self addChildViewController:pageController];
[self.view addSubview:pageController.view];
[pageController didMoveToParentViewController:self];
}
- (UIPageViewController *)pageController
{
return !_pageController ? _pageController =
({
UIPageViewController *value = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll
navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal
options:nil];
value.view.frame = self.view.bounds;
value;
}) : _pageController;
}
- (UIViewController *)pageViewController:(UIPageViewController *)pa geViewController viewControllerBeforeViewController:(UIChildViewController *)viewController
{
NSUInteger index = viewController.index;
return (index == 0 ) ? nil : [self viewControllerAtIndex:--index];
}
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIChildViewController *)viewController
{
NSUInteger index = viewController.index;
index++;
return (index == self.myDataSourceArray.count) ? nil : [self viewControllerAtIndex:index];
}
- (UIChildViewController *)viewControllerAtIndex:(NSUInteger)index
{
UIChildViewController *childViewController = [UIChildViewController new];
childViewController.view.frame = self.pageController.view.bounds;
childViewController.index = index;
...
return childViewController;
}
- (NSInteger)presentationCountForPageViewController: (UIPageViewController *)pageViewController
{
// The number of items reflected in the page indicator.
return self.myDataSourceArray.count;
}
- (NSInteger)presentationIndexForPageViewController:(UI PageViewController *)pageViewController
{
// The selected item reflected in the page indicator.
return 0;
}
The problem was that in including my UIViewController subclass which encapsulated the UIPageViewController, I forgot in the parent view controller's viewDidLoad to include addChildViewController and didMoveToParentViewController
[self addChildViewController:myViewController];
[self.view addSubview:myViewController.view];
[myViewControllerController didMoveToParentViewController:self];
Fixed the problem.

UIPageViewController/TextKit Reflowing Text on paging

I'm working on a multi-page reading application backed by TextKit, based off of the "Advanced Text Layouts and Effects with Text Kit" session from WWDC 2013 (but with some code reconstructed from incomplete example). The basic structure is you calculate the number of pages needed for your text upfront, then create an NSTextContainer for each page and add it to the NSLayoutManager. Whenever the UIPageViewController asks for the next or previous page, you create a new UITextView and set its backing text container by selecting the correct one out of the NLayoutManger's array of NSTextContainers.
Unfortunately, I have a problem where the text gets reflowed both on the first page, and the first time that I page back to any given page. Here's what it look like:
It's not the most glaring effect (if you missed it, pay attention to the top of the screen when paging back), but it is a little disorienting, and I'd like to eliminate it if possible. Given that the text containers should be calculated up front, I don't understand why it's reflowing the text, or how to prevent it. Does anyone know what the problem is?
EDIT: Adding a code sample.
#interface ReaderViewController () <UIPageViewControllerDataSource>
#property (nonatomic, assign) NSUInteger numberOfPages;
#property (nonatomic, retain) UIPageViewController *pageViewController;
#property (nonatomic, retain) NSTextStorage *currentDocument;
#property (nonatomic, retain) NSLayoutManager *layoutManager;
#end
#implementation ReaderViewController
- (instancetype)initWithDocument:(NSTextStorage *)document {
if ((self = [super init])) {
_currentDocument = document;
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
_layoutManager = [[NSLayoutManager alloc] init];
[self.layoutManager setTextStorage:self.currentDocument];
self.layoutManager.delegate = self;
_pageViewController = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll
navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal
options:nil];
self.pageViewController.view.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
self.pageViewController.dataSource = self;
[self addChildViewController:self.pageViewController];
[self.view addSubview:self.pageViewController.view];
// the numberOfPages accessor lazily calculates the number of pages needed to contain the document
for (int i = 0; i < self.numberOfPages; ++i) {
NSTextContainer *container = [[NSTextContainer alloc] init];
container.size = [self _textFrame].size;
[self.layoutManager addTextContainer:container];
}
[self.pageViewController setViewControllers:#[[self viewControllerForPageNumber:0]] direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];
}
- (UIViewController *)viewControllerForPageNumber:(NSUInteger)pageNumber {
if (pageNumber >= self.numberOfPages) {
return nil;
}
// SinglePageViewController is a lightweight view controller that has a UITextView and a page number
SinglePageViewController *vc = [[SinglePageViewController alloc] init];
UITextView *textView = [[UITextView alloc] initWithFrame:[self _textFrame] textContainer:[self.layoutManager.textContainers objectAtIndex:pageNumber]];
textView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
textView.scrollEnabled = NO;
textView.editable = NO;
[textView setFont:[UIFont fontWithName:#"IowanOldStyle-Roman" size:20.f]];
[vc.view addSubview:textView];
vc.textView = textView;
vc.pageNumber = pageNumber;
return vc;
}
#pragma mark - UIPageViewControllerDataSource
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController {
NSUInteger currentPage = [(SinglePageViewController *)viewController pageNumber];
if (currentPage >= self.numberOfPages) {
return nil;
}
return [self viewControllerForPageNumber:currentPage + 1];
}
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController {
NSUInteger currentPage = [(SinglePageViewController *)viewController pageNumber];
if (currentPage == 0) {
return nil;
}
return [self viewControllerForPageNumber:currentPage - 1];
}
#pragma mark - Private
- (CGRect)_textFrame {
return CGRectInset(self.view.bounds, 5., 0.);
}
#end
I faced the same issue. My solution is to put the scrollEnabled after addSubview will force the textContainer re-calculate the size. See below code:
vc.view.addSubview(textView)
textView.scrollEnabled = false;
Update. Finally, I think I found the right answer... We need to reset the container size in the didChangeGeometryFromSize callback. Please correct me if it is not true :)
func layoutManager(layoutManager: NSLayoutManager,
textContainer: NSTextContainer,
didChangeGeometryFromSize oldSize: CGSize) {
textContainer.size = self.textFrame().size;
println(textContainer.size.width)
println(textContainer.size.height)
}
Try to set automaticallyAdjustsScrollViewInsets of your view controller to NO.

how to add two view controllers in UIPageViewcontroller

I m using UIPageViewController on iPad where I need to show a firstviewController in the first page and ContentViewController in the next page in landscape.
If I set the NSArray with two viewControllers the app is crashes at [self.pagviewController setViewController:] with the following exception:
The number of provided view controllers (2) doesn't match the number required (1) for the requested spine location (UIPageViewControllerSpineLocationMin)
Below is the code:
#pragma mark - UIPageViewControllerDataSource Methods
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController
viewControllerBeforeViewController:(UIViewController *)viewController
{
NSUInteger currentIndex = [self.modelArray indexOfObject:[(ContentViewController *)viewController textContents]];
if(currentIndex == 0)
{
return nil;
}
ContentViewController *contentViewController = [[ContentViewController alloc] init];
contentViewController.textContents = [self.modelArray objectAtIndex:currentIndex - 1];
return contentViewController;
}
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController
viewControllerAfterViewController:(UIViewController *)viewController
{
NSUInteger currentIndex = [self.modelArray indexOfObject:[(ContentViewController *)viewController textContents]];
if(currentIndex == self.modelArray.count-1)
{
return nil;
}
ContentViewController *contentViewController = [[ContentViewController alloc] init];
contentViewController.textContents = [self.modelArray objectAtIndex:currentIndex + 1];
return contentViewController;
}
//#pragma mark - UIPageViewControllerDelegate Methods
- (UIPageViewControllerSpineLocation)pageViewController:(UIPageViewController *)pageViewController
spineLocationForInterfaceOrientation:(UIInterfaceOrientation)orientation
{
if(UIInterfaceOrientationIsPortrait(orientation))
{
//Set the array with only 1 view controller
UIViewController *currentViewController = [self.pageViewController.viewControllers objectAtIndex:0];
NSArray *viewControllers = [NSArray arrayWithObject:currentViewController];
[self.pageViewController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:YES completion:NULL];
//Important- Set the doubleSided property to NO.
self.pageViewController.doubleSided = NO;
//Return the spine location
return UIPageViewControllerSpineLocationMin;
}
else
{
NSArray *viewControllers = nil;
ContentViewController *currentViewController = [self.pageViewController.viewControllers objectAtIndex:0];
NSUInteger currentIndex = [self.modelArray indexOfObject:[(ContentViewController *)currentViewController textContents]];
if(currentIndex == 0 || currentIndex %2 == 0)
{
UIViewController *nextViewController = [self pageViewController:self.pageViewController viewControllerAfterViewController:currentViewController];
viewControllers = [NSArray arrayWithObjects:currentViewController, nextViewController, nil];
}
else
{
UIViewController *previousViewController = [self pageViewController:self.pageViewController viewControllerBeforeViewController:currentViewController];
viewControllers = [NSArray arrayWithObjects:previousViewController, currentViewController, nil];
}
//Now, set the viewControllers property of UIPageViewController
[self.pageViewController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:YES completion:NULL];
return UIPageViewControllerSpineLocationMid;
}
}
- (void)viewDidLoad
{
[super viewDidLoad];
appDelegate = (AppDelegate *) [[UIApplication sharedApplication] delegate];
//Instantiate the model array
self.modelArray = [[NSMutableArray alloc] init];
self.vcs = [[NSMutableArray alloc]init];
for (int index = 1; index <= 2 ; index++)
{
[self.modelArray addObject:[NSString stringWithFormat:#"Page %d",index]];
}
//Step 1
//Instantiate the UIPageViewController.
self.pageViewController = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStylePageCurl
navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:nil];
//Step 2:
//Assign the delegate and datasource as self.
self.pageViewController.delegate = self;
self.pageViewController.dataSource = self;
//Step 3:
//Set the initial view controllers.
appDelegate.contentViewController.textContents = [self.modelArray objectAtIndex:0];
NSArray *viewControllers = [NSArray arrayWithObjects:appDelegate.firstViewController,appDelegate.contentViewController,nil];
[self.pageViewController setViewControllers:viewControllers
direction:UIPageViewControllerNavigationDirectionForward
animated:NO
completion:nil];
//Step 4:
//ViewController containment steps
//Add the pageViewController as the childViewController
[self addChildViewController:self.pageViewController];
//Add the view of the pageViewController to the current view
[self.view addSubview:self.pageViewController.view];
//Call didMoveToParentViewController: of the childViewController, the UIPageViewController instance in our case.
[self.pageViewController didMoveToParentViewController:self];
//Step 5:
// set the pageViewController's frame as an inset rect.
CGRect pageViewRect = self.view.bounds;
pageViewRect = CGRectInset(pageViewRect, 40.0, 40.0);
self.pageViewController.view.frame = pageViewRect;
//Step 6:
//Assign the gestureRecognizers property of our pageViewController to our view's gestureRecognizers property.
self.view.gestureRecognizers = self.pageViewController.gestureRecognizers;
}
The problem is you passing an array containing two view controllers to the page view controller while it expects one at a time, change your array to be like this :
NSArray *viewControllers = #[appDelegate.firstViewController];
You will pass one of the views but viewControllerAfterViewController and viewControllerBeforeViewController will handle the rest.
Ah..Finally got solution for this same issue.., it may helps you..
When we set the spine location to UIPageViewControllerSpineLocationMid, the doubleSided property of the pageViewController is automatically set to YES. This means that the content on page front will not partially show through back. But when this property is set to NO, the content on page front will partially show through back, giving the page a translucent kind of effect. So, in the portrait orientation, we have to set the value to NO, otherwise it would result in an exception.
So in your UIPageviewcontroller delegate method, in else part add this doubleSided property as YES when you return spineLocation as UIPageViewControllerSpineLocationMid
self.pageViewController.doubleSided = YES;
return UIPageViewControllerSpineLocationMid;
self.pageViewController.doubleSided = NO;
return UIPageViewControllerSpineLocationMid;
This is the solution for the exception.
In xcode it self you could find this.
Go to the UIPageViewcontroller class there you could see the explanation for this like:
#property (nonatomic, readonly) UIPageViewControllerSpineLocation spineLocation; // If transition style is 'UIPageViewControllerTransitionStylePageCurl', default is 'UIPageViewControllerSpineLocationMin', otherwise 'UIPageViewControllerSpineLocationNone'.
// Whether client content appears on both sides of each page. If 'NO', content on page front will partially show through back.
// If 'UIPageViewControllerSpineLocationMid' is set, 'doubleSided' is set to 'YES'. Setting 'NO' when spine location is mid results in an exception.
#property (nonatomic, getter=isDoubleSided) BOOL doubleSided; // Default is 'NO'.
Instead of implementing a full data source, you can set the PageViewController with one view controller at a time each time the user pushes a next or back button, like
[pageViewController setViewControllers:#[contentViewController]
direction:UIPageViewControllerNavigationDirectionForward
animated:YES
completion:nil];
This will animate the page transition as you switch.

How to Move Left and Righ of when people flip UIImageView so it looks like it's really going left and right

The style should be like iBooks or pictures in foursquare. When we flip to the left we see the next picture being pulled. How to do so? Is there a code to do so? I think there must have been a ready code for that
It sounds like you want UIPageViewController.
Try this. One solution. Revise as needed.
Create a new project of type Single View Application, name it BookEffect, uncheck Use Storyboards, uncheck Include Unit Tests, but be sure to check the option Use Automatic Reference Counting.
Then add to the project a few pictures, for example, in JPEG format.
Create a new file - use the Objective-C Class template with a subclass of UIViewController, select the option With XIB for user interface, and name it SinglePageViewController. Save the file inside the BookEffect folder.
Once added, select the SinglePageViewController.xib and add to the view a UILabel control and UIImageView control and make the appropriate connections to the File's Owner.
Revise the SinglePageViewController.h to look like this:
#import <UIKit/UIKit.h>
#interface SinglePageViewController : UIViewController
{
NSUInteger pageNumber;
}
#property (strong, nonatomic) IBOutlet UILabel *titleLabel;
#property (strong, nonatomic) IBOutlet UIImageView *imageView;
#property (nonatomic, assign) NSUInteger pageNumber;
- (void) setPageNumber: (NSUInteger) newPageNumber;
- (NSUInteger) pageNumber;
#end
In SinglePageViewController.m add:
#synthesize imageView, titleLabel;
and add these definitions of methods:
- (void) setPageNumber: (NSUInteger) newPageNumber{
pageNumber = newPageNumber;
}
- (NSUInteger) pageNumber{
return pageNumber;
}
- (void) viewDidAppear:(BOOL)animated{
[super viewDidAppear:animated];
[titleLabel setText:[NSString stringWithFormat:#"Page %d", pageNumber]];
NSArray *images = [[NSBundle mainBundle] pathsForResourcesOfType:#".jpg" inDirectory:nil];
UIImage *img = [UIImage imageWithContentsOfFile:[images objectAtIndex:pageNumber-1]];
[imageView setImage:img];
}
Now go to the BookEffecViewController.h, and make it look like this:
#import <UIKit/UIKit.h>
#import "SinglePageViewController.h"
#interface BookEffectViewController : UIViewController
<UIPageViewControllerDataSource>
#property( nonatomic, strong) UIPageViewController *pageViewController;
#end
In BookEffectViewController.m revise viewDidLoad to look like this:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.pageViewController = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStylePageCurl navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:nil];
self.pageViewController.dataSource = self;
SinglePageViewController *singlePage = [[SinglePageViewController alloc] initWithNibName:#"SinglePageViewController" bundle:nil];
[singlePage setPageNumber:1];
NSArray *controllers = [[NSArray alloc] initWithObjects:singlePage, nil];
[self.pageViewController setViewControllers:controllers direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];
[self addChildViewController:self.pageViewController];
[self.view addSubview:self.pageViewController.view];
self.pageViewController.view.frame = self.view.bounds;
}
Define two more methods in BookEffectViewController.m:
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController
{
NSUInteger previousPageNumber = [((SinglePageViewController*)viewController) pageNumber];
if ( previousPageNumber == 1 ) {
return nil;
}
else{
SinglePageViewController *singlePage = [[SinglePageViewController alloc] initWithNibName:#"SinglePageViewController" bundle:nil];
[singlePage setPageNumber:previousPageNumber-1];
return singlePage;
}
}
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController
{
NSUInteger previousPageNumber = [((SinglePageViewController*)viewController) pageNumber];
if ( previousPageNumber >= [[[NSBundle mainBundle] pathsForResourcesOfType:#".jpg" inDirectory:nil] count] ) {
return nil;
}
else{
SinglePageViewController *singlePage = [[SinglePageViewController alloc] initWithNibName:#"SinglePageViewController" bundle:nil];
[singlePage setPageNumber:previousPageNumber+1];
return singlePage;
}
}
That's it. Command-R to test it with the iPad Simulator
This is a basic shell and other bells and whistles can be added for your own pleasure, i.e. take out Page Number, add a caption, etc.
Hope this helped.

Resources