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

  • SEARCH
  • Home
  • 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 8299557
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T16:11:49+00:00 2026-06-08T16:11:49+00:00

I have a VC with a scrollview and pagecontrol implemented in it. It has

  • 0

I have a VC with a scrollview and pagecontrol implemented in it. It has three pages, which are all set up correctly and working fine. What I want to be able to do is have the VC load onto different pages depending on what button a user presses.

In the method the button calls I have

ViewController *vc = [[ViewController alloc] init];
vc.pageControl.currentPage = 2;
[self.navigationController pushViewController:vc animated:YES]; 

When the VC loads, it is loaded onto the correct page (as evidenced by the bubbles at the bottom of the page) but it is displaying the information from page[0]. If I start scrolling, it jumps back to page[0] no matter what I do.

My best guess is that I need to make the VC load to a specific x origin depending on what page I want to display, but I haven’t been able to find anything related to this, so I’m quite lost.

Appreciate any help.

EDIT: Here is the code from the VC class. I didn’t write this and it is my first time working with PageControl, so I’m trying to learn as I go.

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {

    self.scrollView = [[UIScrollView alloc] init];
    self.scrollView.pagingEnabled = TRUE;
    self.scrollView.showsVerticalScrollIndicator = NO;
    self.scrollView.showsHorizontalScrollIndicator = NO;
    self.scrollView.delegate = self;

    firstPage = [[UIView alloc] init];
    firstPage.tag = 0;

    secondPage = [[UIView alloc] init];
    secondPage.tag = 1;

    thirdPage = [[UIView alloc] init];
    thirdPage.tag = 2;

    pages = [[NSArray alloc] initWithObjects:firstPage, secondPage, thirdPage, nil];

    // Page Control
    self.pageControl = [[UIPageControl alloc] init];
    self.pageControl.numberOfPages = 3;
    self.pageControl.currentPage = 0;

    [self.view addSubview:self.scrollView];
    [self.view addSubview:self.pageControl];
}
return self;
}

- (void)viewDidLoad
{
[super viewDidLoad];

// First Page Setup
//
[self setupFirstPage];

// Second Page Setup
//
[self setupSecondPage];

// Third Page Setup
//
[self setupThirdPage];

// Frame everything
//
CGRect screenFrame = [[UIScreen mainScreen] applicationFrame];
CGRect navBarFrame = self.navigationController.navigationBar.frame;

self.scrollView.frame = CGRectMake(0, navBarFrame.size.height, 320, screenFrame.size.height - navBarFrame.size.height);
self.pageControl.frame = CGRectMake(0, screenFrame.size.height - 70, 320, 20);

firstPage.frame = CGRectMake(0, 0, self.scrollView.frame.size.width, self.scrollView.frame.size.height);
secondPage.frame = CGRectMake(320 * secondPage.tag, 0, self.scrollView.frame.size.width, self.scrollView.frame.size.height);
thirdPage.frame = CGRectMake(320 * thirdPage.tag, 0, self.scrollView.frame.size.width, self.scrollView.frame.size.height);

// Add Subviews
//
[self.scrollView addSubview:firstPage];
[self.scrollView addSubview:secondPage];
[self.scrollView addSubview:thirdPage];

self.scrollView.contentSize = CGSizeMake(320 * pages.count, self.scrollView.frame.size.height);
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
CGFloat pageWidth = self.scrollView.frame.size.width;
int page = floor((self.scrollView.contentOffset.x - pageWidth / 2) / pageWidth) + 1;
self.pageControl.currentPage = page;
}
  • 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-06-08T16:11:50+00:00Added an answer on June 8, 2026 at 4:11 pm

    Try adding this function and calling it right after you set the page number:

    - (void)pageSelectorChanged 
    {
        CGRect frame = self.scrollView.frame;
        frame.origin.x = frame.size.width * self.pageControl.currentPage;
        frame.origin.y = 0;
        [self.scrollView scrollRectToVisible:frame animated:NO];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a scrollview which has to display a view larger than the available
I have a scrollView with paging enabled and a number N of pages, which
I have a scrollview with 25 pages (pagingEnabled) and i want to put a
I have a ScrollView which has two hidden images, one at the top and
I have a ScrollView and a very long text on TextView and I want
I have a scrollview control that has a StackPanel (Orientation=Vertical) UI Element inside of
I have a scrollview in which i am creating buttons programmatically. On touch, button
Actually i want to implement swipe left and right in UIScrollview. i have scrollview
I have a scrollview that always shows three items. I need the middle item
I have a page control and a scrollview implemented in one of my views.

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.