I bought this project (http://codecanyon.net/item/turnthepdf/2417301/support) to use in my application but it is not detecting links inside PDF file. For example, page index works in webview but not working in this library.
I tried to search in internet about configuring UIPageViewController but no result.
#pragma mark Debug / Utility
- (int) currentPage
{
int pageCheck = ((UIViewController *)[self.viewControllers objectAtIndex:0]).view.tag;
return pageCheck;
}
#pragma mark Page Handling
// Update if you'd rather use some other decision style
- (BOOL) useSideBySide: (UIInterfaceOrientation) orientation
{
BOOL isLandscape = UIInterfaceOrientationIsLandscape(orientation);
return isLandscape;
}
// Store the new page and update the delgate
- (void) updatePageTo: (uint) newPageNumber
{
pageNumber = newPageNumber;
[[NSUserDefaults standardUserDefaults] setInteger:pageNumber forKey:DEFAULTS_BOOKPAGE];
[[NSUserDefaults standardUserDefaults] synchronize];
SAFE_PERFORM_WITH_ARG(bookDelegate, #selector(bookControllerDidTurnToPage:), [NSNumber numberWithInt:pageNumber]);
}
// Request controller from delegate
- (UIViewController *) controllerAtPage: (int) aPageNumber
{
if (bookDelegate &&
[bookDelegate respondsToSelector:#selector(viewControllerForPage:)])
{
UIViewController *controller = [bookDelegate viewControllerForPage:aPageNumber];
controller.view.tag = aPageNumber;
return controller;
}
return nil;
}
// Update interface to the given page
- (void) fetchControllersForPage: (uint) requestedPage orientation: (UIInterfaceOrientation) orientation
{
BOOL sideBySide = [self useSideBySide:orientation];
int numberOfPagesNeeded = sideBySide ? 2 : 1;
int currentCount = self.viewControllers.count;
uint leftPage = requestedPage;
if (sideBySide && (leftPage % 2)) leftPage--;
// Only check against current page when count is appropriate
if (currentCount && (currentCount == numberOfPagesNeeded))
{
if (pageNumber == requestedPage) return;
if (pageNumber == leftPage) return;
}
// Decide the prevailing direction by checking the new page against the old
UIPageViewControllerNavigationDirection direction = (requestedPage > pageNumber) ? UIPageViewControllerNavigationDirectionForward : UIPageViewControllerNavigationDirectionReverse;
[self updatePageTo:requestedPage];
// Update the controllers
NSMutableArray *pageControllers = [NSMutableArray array];
SAFE_ADD(pageControllers, [self controllerAtPage:leftPage]);
if (sideBySide)
SAFE_ADD(pageControllers, [self controllerAtPage:leftPage + 1]);
[self setViewControllers:pageControllers direction: direction animated:YES completion:nil];
}
- (void)viewDidLoad {
}
// Entry point for external move request
- (void) moveToPage: (uint) requestedPage
{
[self fetchControllersForPage:requestedPage orientation:(UIInterfaceOrientation)[UIDevice currentDevice].orientation];
}
#pragma mark Data Source
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController
{
[self updatePageTo:pageNumber - 1];
return [self controllerAtPage:(viewController.view.tag - 1)];
}
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController
{
[self updatePageTo:pageNumber + 1];
return [self controllerAtPage:(viewController.view.tag + 1)];
}
/*
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController
{
[self updatePageTo:pageNumber + 1];
return [self controllerAtPage:(viewController.view.tag + 1)];
}
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController
{
[self updatePageTo:pageNumber - 1];
return [self controllerAtPage:(viewController.view.tag - 1)];
}
*/
#pragma mark Delegate
- (UIPageViewControllerSpineLocation)pageViewController:(UIPageViewController *)pageViewController spineLocationForInterfaceOrientation:(UIInterfaceOrientation)orientation
{
NSUInteger indexOfCurrentViewController = 0;
if (self.viewControllers.count)
indexOfCurrentViewController = ((UIViewController *)[self.viewControllers objectAtIndex:0]).view.tag;
[self fetchControllersForPage:indexOfCurrentViewController orientation:orientation];
BOOL sideBySide = [self useSideBySide:orientation];
self.doubleSided = sideBySide;
UIPageViewControllerSpineLocation spineLocation = sideBySide ? UIPageViewControllerSpineLocationMid : UIPageViewControllerSpineLocationMin;
return spineLocation;
}
#pragma mark Class utility routines
// Return a UIViewController that knows how to rotate
+ (id) rotatableViewController
{
UIViewController *vc = [[RotatableVC alloc] init];
return vc;
}
// Return a new book
+ (id) bookWithDelegate: (id) theDelegate
{
BookController *bc = [[BookController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStylePageCurl navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:nil];
bc.dataSource = bc;
bc.delegate = bc;
bc.bookDelegate = theDelegate;
return bc;
}
Annotations inside a pdf is not able to render in iOS devices to render forms or annotations you can go for a good library.
Pdf Tron Library
You can also see the below link it might help.
Get pdf hyperlinks on ios
Related
I am doing a tutorial in my iOS app. But I have a bug in my PageViewController.
My tutorial has 5 pages. But the second movement that I do to change page always appears the previous page repeatedly.
For example, appears page0, move to page1, and then when i want to appear page2, appears page1 again.
This occurs to both sides.
This is my code:
- (void)viewDidLoad {
[super viewDidLoad];
self.pageTexts = #[#"",intro1, intro2, intro3, intro4];
self.index = 0;
self.viewControllerPageContentOne = [[ViewControllerPageContentOne alloc] init];
self.viewControllerPageContentTwo = [[ViewControllerPageContentTwo alloc] init];
self.viewControllerPageContentThree = [[ViewControllerPageContentThree alloc] init];
self.pageViewController = [self.storyboard instantiateViewControllerWithIdentifier:#"PageViewController"];
self.pageViewController.dataSource = self;
UIViewController* first = [self viewControllerUsed];
NSArray *viewControllers = [NSArray arrayWithObject:first];
[self.pageViewController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];
[self addChildViewController:self.pageViewController];
[self.view addSubview:self.pageViewController.view];
[self.pageViewController didMoveToParentViewController:self];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
- (UIViewController *)viewControllerUsed{
if (self.index == 0) {
self.viewControllerPageContentOne=[self.storyboard instantiateViewControllerWithIdentifier:#"ViewControllerPageContentOne"];
return self.viewControllerPageContentOne;
}
else if (self.index == 1)
{
self.viewControllerPageContentTwo=[self.storyboard instantiateViewControllerWithIdentifier:#"ViewControllerPageContentTwo"];
self.viewControllerPageContentTwo.titleText = self.pageTexts[self.index];
return self.viewControllerPageContentTwo;
}
else if (self.index == 2)
{
self.viewControllerPageContentTwo=[self.storyboard instantiateViewControllerWithIdentifier:#"ViewControllerPageContentTwo"];
self.viewControllerPageContentTwo.titleText = self.pageTexts[self.index];
return self.viewControllerPageContentTwo;
}
else if (self.index == 3)
{
self.viewControllerPageContentTwo=[self.storyboard instantiateViewControllerWithIdentifier:#"ViewControllerPageContentTwo"];
self.viewControllerPageContentTwo.titleText = self.pageTexts[self.index];
return self.viewControllerPageContentTwo;
}
else if (self.index == 4)
{
self.viewControllerPageContentThree=[self.storyboard instantiateViewControllerWithIdentifier:#"ViewControllerPageContentThree"];
self.viewControllerPageContentThree.titleText = self.pageTexts[self.index];
return self.viewControllerPageContentThree;
}
else{
return nil;
}
}
#pragma mark - Page View Controller Data Source
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController {
self.index--;
if (self.index < 0) {
self.index = [self.pageTexts count]-1;
}
return [self viewControllerUsed];
}
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController {
self.index++;
if (self.index > [self.pageTexts count]-1) {
self.index = 0;
}
return [self viewControllerUsed];
}
- (NSInteger)presentationCountForPageViewController:(UIPageViewController *)pageViewController
{
return [self.pageTexts count];
}
- (NSInteger)presentationIndexForPageViewController:(UIPageViewController *)pageViewController
{
return 0;
}
I suppose that there is an error in index pages but I don’t know it.
Thanks
I think your problem is that you are creating class level properties for view controllers. And that too you are initialising them in viewDidLoad
self.viewControllerPageContentOne = [[ViewControllerPageContentOne alloc] init];
self.viewControllerPageContentTwo = [[ViewControllerPageContentTwo alloc] init];
self.viewControllerPageContentThree = [[ViewControllerPageContentThree alloc] init];
My advise is to create view controllers and save them in an array like this:
UIViewController *page0 = [self.storyboard instantiateViewControllerWithIdentifier:#"ViewControllerPageContentOne"];
UIViewController *page1 = [self.storyboard instantiateViewControllerWithIdentifier:#"ViewControllerPageContentTwo"]
page3.titleText = self.pageTexts[1];
UIViewController *page2 = [self.storyboard instantiateViewControllerWithIdentifier:#"ViewControllerPageContentTwo"]
page3.titleText = self.pageTexts[2];
UIViewController *page3 = [self.storyboard instantiateViewControllerWithIdentifier:#"ViewControllerPageContentTwo"]
page3.titleText = self.pageTexts[3];
UIViewController *page4 = [self.storyboard instantiateViewControllerWithIdentifier:#"ViewControllerPageContentThree"];
[self.viewControllers addObject:page0];
[self.viewControllers addObject:page1];
[self.viewControllers addObject:page2];
[self.viewControllers addObject:page3];
[self.viewControllers addObject:page4];
And then in your viewControllerUsed simply return viewControllers from self.viewControllers like self.viewControllers[self.index].
I have a pageViewController which brings different images to the screen on each swipe. The paging works with the gesture great. However, I am trying to implement a button which does the paging as well. I have a button on the top left called "Back" and a button on the top right called "Next". I can't get these buttons to work.
Note: OnboardingChildViewController is the child controller of LoginSignUpController
Code:
LoginSignUpViewController.m:
#pragma mark - Paging delegate
- (OnboardingChildViewController *)viewControllerAtIndex:(NSUInteger)index {
OnboardingChildViewController *childViewController = [[OnboardingChildViewController alloc] initWithNibName:#"OnboardingChildViewController" bundle:nil];
childViewController.index = index;
return childViewController;
}
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController {
NSUInteger index = [(OnboardingChildViewController *)viewController index];
if (index == 0) {
return nil;
}
// Decrease the index by 1 to return
index--;
return [self viewControllerAtIndex:index];
}
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController {
NSUInteger index = [(OnboardingChildViewController *)viewController index];
index++;
if (index == 5) {
return nil;
}
return [self viewControllerAtIndex:index];
}
- (NSInteger)presentationCountForPageViewController:(UIPageViewController *)pageViewController {
// The number of items reflected in the page indicator.
return 5;
}
- (NSInteger)presentationIndexForPageViewController:(UIPageViewController *)pageViewController {
// The selected item reflected in the page indicator.
return 0;
}
OnboardingChildViewController.m:
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor clearColor];
switch(self.index)
{
case 0: {
self.dismissButton.hidden = true;
self.onboardingImage.image = nil;
[self.nextButton setTitle:#"Take a Tour" forState:UIControlStateNormal];
self.onboardingDescription.hidden = true;
self.index = 0;
break;
}
case 1: {
self.dismissButton.hidden = false;
self.onboardingImage.image = [UIImage imageNamed: #"onboardingImage1.png"];
self.onboardingDescription.text = #"Follow users to see their content in your feed";
self.index = 1;
break;
}
case 2: {
self.dismissButton.hidden = false;
self.onboardingImage.image = [UIImage imageNamed: #"onboardingImage2.png"];
self.onboardingDescription.text = #"Listen to Stations based on your interest";
self.index = 2;
break;
}
case 3: {
self.dismissButton.hidden = false;
self.onboardingImage.image = [UIImage imageNamed: #"onboardingImage3.png"];
self.onboardingDescription.text = #"Easily Search for Users, Posts, and Stations";
self.index = 3;
break;
}
default: {
self.dismissButton.hidden = false;
self.onboardingImage.image = [UIImage imageNamed: #"onboardingImage4.png"];
[self.nextButton setTitle:#"Sign Up" forState:UIControlStateNormal];
self.onboardingDescription.text = #"Post Photos, Videos, Audio, and Live Video to Stations";
self.index = 4;
break;
}
}
}
- (IBAction)backButton:(id)sender {
//NEED TO MOVE PAGEVIEWCONTROLLER BACK.... self.index--?
}
- (IBAction)nextButton:(id)sender {
//NEED TO MOVE PAGEVIEWCONTROLLER FORWARD.... self.index++?
}
Call setViewControllers and pass in the ViewController you want to display
https://developer.apple.com/library//ios/documentation/UIKit/Reference/UIPageViewControllerClassReferenceClassRef/index.html#//apple_ref/occ/instm/UIPageViewController/setViewControllers:direction:animated:completion:
I am loading multiple UIViewControllers in UIPageViewController with each UIViewController having their own navigation bar. I have implemented all the required data source and delegate methods for UIPageViewController and it showing up correctly.
But when I scroll my view controller horizontally, more often, I see a white blank screen instead of my view controller. Below is my code.
Any clue what could be wrong here.
PS: I tried by removing the IF condition in my viewControllerForRequestID method and returning a new controller every time. This works but then I end up with one view controller showing up twice in pagination.
- (UIViewController *)pageViewController:(UIPageViewController *)iPageViewController viewControllerBeforeViewController:(UIViewController *)iViewController {
[self.pageControl setCurrentPage:self.selectedRequestIndex];
if (self.selectedRequestIndex == 0) {
return nil;
}
NSUInteger aNewSelectedRequestIndex = self.selectedRequestIndex - 1;
NSString *aPreviousRequestID = [self.paginationRequestIDList[aNewSelectedRequestIndex] stringValue];
self.selectedRequestIndex = aNewSelectedRequestIndex;
self.selectedRequestID = aPreviousRequestID;
return [self viewControllerForRequestID:self.selectedRequestID];
}
- (UIViewController *)pageViewController:(UIPageViewController *)iPageViewController viewControllerAfterViewController:(UIViewController *)iViewController {
[self.pageControl setCurrentPage:self.selectedRequestIndex];
if (self.selectedRequestIndex == NSNotFound || self.selectedRequestIndex >= self.paginationRequestIDList.count - 1) {
return nil;
}
NSUInteger aNewSelectedRequestIndex = self.selectedRequestIndex + 1;
NSString *aNextRequestID = self.paginationRequestIDList[aNewSelectedRequestIndex];
self.selectedRequestIndex = aNewSelectedRequestIndex;
self.selectedRequestID = aNextRequestID;
return [self viewControllerForRequestID:self.selectedRequestID];
}
- (MyNavigationViewController *)viewControllerForRequestID:(id)iRequestID {
NSString *aRequestID = iRequestID;
// Safe check to avoid numbers in request ID
if (![iRequestID isKindOfClass:[NSString class]]) {
aRequestID = [iRequestID stringValue];
}
#synchronized (self) {
if ([self.viewControllers containsObjectForKey:iRequestID]) {
MyNavigationViewController *aNavigationController = self.viewControllers[iRequestID];
return aNavigationController;
}
MyDataModel *aRequestData = self.savedRequestData[iRequestID];
MyDataModelController *aRequestInfoController = [[MyDataModelController alloc] initWithRequestData:aRequestData];
aRequestInfoController.delegate = self;
MyNavigationViewController *aNavigationController = [[MyNavigationViewController alloc] initWithRootViewController:aRequestInfoController];
[self.viewControllers setObject:aNavigationController forKey:iRequestID];
return aNavigationController;
}
}
I have a slight problem with my code. I keep getting the following message appear when I try to I have two page view controllers in my application. Both are being used for different things. I copied and pasted my coding for the first page controller I implemented and then I changed around the names to prevent conflicts. I recently started to recieve this error message and now my program can no longer work. Can anyone please tell me why this happens?
I also get an error which says method 'pageViewController:viewControllerBeforeViewController:' in protocol not implemented. Im not too sure if this is a linked problem, but does anyone know why I get this?
#import "StorageViewController.h"
#import "InstructionContentViewController.h"
#interface StorageViewController ()
#end
#implementation StorageViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Create the data model
_pageInstructTitles = #[#"Over 200 Tips and Tricks", #"Discover Hidden Features", #"Bookmark Favorite Tip", #"Free Regular Update"];
_pageInstructImages = #[#"instructions1.png", #"instructions2.png", #"instructions3.png", #"instructions4.png"];
// Create page view controller
self.instructViewController = [self.storyboard instantiateViewControllerWithIdentifier:#"InstructionViewController"];
self.instructViewController.dataSource = self;
InstructionContentViewController *startingInstructViewController = [self viewControllerAtIndex:0];
NSArray *viewInstructControllers = #[startingInstructViewController];
[self.instructViewController setViewControllers:viewInstructControllers direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];
// Change the size of page view controller
self.instructViewController.view.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height - 30);
[self addChildViewController:_instructViewController];
[self.view addSubview:_instructViewController.view];
[self.instructViewController didMoveToParentViewController:self];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)startInstructWalkthrough:(id)sender {
InstructionContentViewController *startingInstructViewController = [self viewControllerAtIndex:0];
NSArray *viewControllers = #[startingInstructViewController];
[self.instructViewController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionReverse animated:NO completion:nil];
}
#pragma mark - Page View Controller Data Source Methods:
- (UIViewController *)instructViewController:(UIPageViewController *)instructViewController viewControllerBeforeViewController:(UIViewController *)viewInstructController
{
NSUInteger index = ((InstructionContentViewController*) viewInstructController).instructPageIndex;
if ((index == 0) || (index == NSNotFound)) {
return nil;
}
index--;
return [self viewControllerAtIndex:index];
}
- (UIViewController *)instructViewController:(UIPageViewController *)instructViewController viewControllerAfterViewController:(UIViewController *)viewInstructController
{
NSUInteger index = ((InstructionContentViewController*) viewInstructController).instructPageIndex;
if (index == NSNotFound) {
return nil;
}
index++;
if (index == [self.pageInstructTitles count]) {
return nil;
}
return [self viewControllerAtIndex:index];
}
- (InstructionContentViewController *)viewControllerAtIndex:(NSUInteger)index
{
if (([self.pageInstructTitles count] == 0) || (index >= [self.pageInstructTitles count])) {
return nil;
}
// Create a new view controller and pass suitable data.
InstructionContentViewController *instructionContentViewController = [self.storyboard instantiateViewControllerWithIdentifier:#"InstructionContentViewController"];
instructionContentViewController.instructImageFile = self.pageInstructImages[index];
instructionContentViewController.instructTitleText = self.pageInstructTitles[index];
instructionContentViewController.instructPageIndex = index;
return instructionContentViewController;
}
- (NSInteger)presentationCountForPageViewController:(UIPageViewController *)instructViewController
{
return [self.pageInstructTitles count];
}
- (NSInteger)presentationIndexForPageViewController:(UIPageViewController *)instructViewController
{
return 0;
}
#end
I've been trying to use the UIPageViewController to display 3 different nibs for a few days on and off now and have almost got it working. I still have one weird bug that I cant figure out.
Basically the app starts, I can scroll between the 3 pages one after another with out any problems, eg:
Page1->Page2->Page3
and then back to the start:
Page3->Page2->Page1.
No Problems. The issue is that if I scroll, for example from Page3->Page2, then BACK to Page3, Page3 Dissappears when it snaps into place. If I scroll to where a forth page would be, then I get Page3. Here is the code relevant to the UIPageViewController, the nibs and the delegate methods for the UIPageViewController:
- (void)viewDidLoad{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.pageViewController = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:nil];
self.pageViewController.delegate = self;
[[self.pageViewController view] setFrame:[[self view] bounds]];
indexTest = 0;
Page1 *p1 = [[Page1 alloc]initWithNibName:#"Page1" bundle:nil];
p1.view.tag = 1;
Page2 *p2 = [[Page2 alloc]initWithNibName:#"Page2" bundle:nil];
p2.view.tag = 2;
Page3 *p3 = [[Page3 alloc]initWithNibName:#"Page3" bundle:nil];
p3.view.tag = 3;
NSArray *arr = [[NSArray alloc] initWithObjects:p1,nil];
viewControllers = [[NSMutableArray alloc] initWithObjects:p1,p2,p3, nil];
[self.pageViewController setViewControllers:arr direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];
self.pageViewController.dataSource = self;
[self addChildViewController:self.pageViewController];
[[self view] addSubview:[self.pageViewController view]];
[self.pageViewController didMoveToParentViewController:self];
self.view.gestureRecognizers = self.pageViewController.gestureRecognizers;
}
#pragma mark - page view controller stuff
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController {
if (indexTest > 0) {
switch (indexTest) {
case 1:{
NSLog(#"NO page is BEFORE current page");
break;
}
case 2:{
NSLog(#"Page BEFORE is Page: %#", [NSString stringWithFormat:#"%#",[viewControllers objectAtIndex:0] ] );
indexTest--;
return [viewControllers objectAtIndex:0];
break;
}
default:{
NSLog(#"PROBLEM in viewBEFORE, indexTest = %d!!!!", indexTest);
break;
}
}
}
return nil;
}
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController {
if (indexTest < NUM_OF_PAGES) {
switch (indexTest) {
case 0:{
NSLog(#"Page AFTER is Page: %#", [NSString stringWithFormat:#"%#",[viewControllers objectAtIndex:1] ] );
indexTest++;
return [viewControllers objectAtIndex:1];
break;
}
case 1:{
NSLog(#"Page AFTER is Page: %#", [NSString stringWithFormat:#"%#",[viewControllers objectAtIndex:2] ] );
indexTest++;
return [viewControllers objectAtIndex:2];
break;
}
case 2:{
NSLog(#"No pages AFTER this current page %d", indexTest);
break;
}
default:{
NSLog(#"PROBLEM in viewAFTER, indexTest = %d!!!!", indexTest);
break;
}
}
}
return nil;
}
Finally the page index dots code
#pragma mark - dot controller
- (NSInteger)presentationCountForPageViewController:(UIPageViewController *)pageViewController {
// The number of items reflected in the page indicator.
return NUM_OF_PAGES;
}
- (NSInteger)presentationIndexForPageViewController:(UIPageViewController *)pageViewController {
// The selected item reflected in the page indicator.
return 0;
}
Any and all help is much appreciated, I think I'm just doing something silly that I cant see as I'm so close to it fully working. If anythings not clear or I haven't give enough information please let me know and I'll answer it as best as I can.
Thanks
I think your indexTest logic is wrong, it's showing the wrong indexes for the viewControllers. I wouldn't use those methods to keep track of the index as they can be called even when the views aren't actually going to change.
Instead you could replace the selection of view controllers like this:
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController {
int vcIndex = [self.viewControllers indexOfObject:viewController];
if (vcIndex > 0) {
return [self.viewControllers objectAtIndex:vcIndex-1];
}
return nil;
}
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController {
int vcIndex = [self.viewControllers indexOfObject:viewController];
if (vcIndex < NUM_OF_PAGES-1) {
return [self.viewControllers objectAtIndex:vcIndex+1];
}
return nil;
}
And if you need to keep track of the current index, use the delegate method provided.
- (void)pageViewController:(UIPageViewController *)pageViewController didFinishAnimating:(BOOL)finished previousViewControllers:(NSArray *)previousViewControllers transitionCompleted:(BOOL)completed {
if (completed && finished) {
UIViewController *currentVC = pageViewController.viewControllers[0];
indexTest = [self.viewControllers indexOfObject:currentVC];
}
}
Just note that if your using this method, don't call setViewControllers: amimated:YES as this will lose track of the correct position.
Side note: I too have been struggling with UIPageViewController and found it was quicker and easier to write my own version. I think it has too many bugs.