Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7677315
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T17:23:42+00:00 2026-05-31T17:23:42+00:00

I have a UIPageViewController that uses an integer to tell which page it is

  • 0

I have a UIPageViewController that uses an integer to tell which page it is on. It works fine, but if the user quickly swipes several times to get to a page further back, the integer changes more quickly than the views do, and then the whole thing falls apart (the app thinks it is on page 7 when it could be displaying page 3). What am I doing wrong? Is there a different method I should use to tell where I am? Thanks.

- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController {
    if (pageNumber == 0) {
        pageNumber++;
        NSLog(@"%i", pageNumber);
        Two *two = [[Two alloc] init];
        return two;
    } else if (pageNumber == 1) {
        pageNumber++;
        NSLog(@"%i", pageNumber);
        Three *three = [[Three alloc] init];
        return three;
    } else if (pageNumber >= 2) {
        return nil;
    } else {
        return nil;
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T17:23:43+00:00Added an answer on May 31, 2026 at 5:23 pm

    The problem is that you’re taking pageNumber for granted. UIPageViewController could only be asking for next viewController to preload it and you’re already increasing pageNumber.

    You were close when you noticed that “this also happens if a user grabs the edge of the page and starts to move it, but then puts it and back stays on the current page.”

    This method gets UIViewController for parameter and that is the only real reference you have.

    Since you only have three pages one way to solve this would be:

    - (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController
    {
        if ([viewController isKindOfClass: [One class]])
        {
            Two *two = [[Two alloc] init];
            return two;
        }
        else if ([viewController isKindOfClass: [Two class]])
        {
            Three *three = [[Three alloc] init];
            return three;
        }
        else
        {
            return nil;
        }
    }
    

    Note: this code is not the best solution – i’m just trying to point out that you shouldn’t be simply increasing/decreasing pageNumber in viewControllerAfterViewController:/viewControllerBeforeViewController:

    You could also [[... alloc ]init] viewControllers before all this and reduce initialization activity of viewControllers in UIPageViewControllerDataSource methods to loadView (if it’s not loaded) at most. For example (abbreviated):

        ...
        if ([viewController isKindOfClass: [One class]])
        {
            //Two *two = [[Two alloc] init]; //called before and two is someone's property
            if (![two isViewLoaded]) [two loadView];
            return two;
        }
        else if ...
    

    For more pages you could also try tagging viewControllers (during their initialization). Since UIViewController itself doesn’t have a tag property you could probably use viewController.view.tag or sublcass UIViewController and add it a pageNumber property (this would probably be close to THE solution.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a UIPageViewController with several pages. Each page is the same view controller,
Have a fun issue with sharepoint calendar view filtering. That code works fine: SPSecurity.RunWithElevatedPrivileges(delegate()
I have a UIPageViewController load with my Viewcontroller. The view controllers have buttons which
I'm on Monotouch 5.2.6 and iOS SDK 5.0.1. I have a UIPageViewController that is
Have two separate databases. The master that holds the user information(username, password, address etc.).
Have a SomeLib.pro file that contains: CONFIG += debug TEMPLATE = lib TARGET =
Have a matrix report now that has Position, Hours and Wages for a location
have not tested on windows. but in ubuntu when u disconnect from the network,
I have several buttons positioned on my ViewController within the area covered by the
Have converted devise new session from erb to Haml but doens't work, this is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.