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 6811115
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:17:17+00:00 2026-05-26T20:17:17+00:00

I am interested in using a page control to switch through entries in my

  • 0

I am interested in using a page control to switch through entries in my array without changing the view. How can I do this? Is there a tutorial. . .

However, whenever the pages is switched, the background color and some images change. Is there any way to run code once a page is switched?

Thanks

  • 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-26T20:17:17+00:00Added an answer on May 26, 2026 at 8:17 pm

    UIPageControl only represents paging, it does not manage the paging behavior itself. You will need to write your own code to iterate through your array when clicking on the UIPageControl. The currentPage property should be set to the index you are working with in your array, the totalPages property should be set to the array’s count property. Finally, you’ll need to setup a target/action pair for the UIControlEventValueChanged event using -addTarget:action:forControlEvents:

    [pageControl addTarget:self action:@selector(pageChanged:) forControlEvents:UIControlEventValueChanged];
    

    The documentation states:

    When a user taps a page control to move to the next or previous page, the control sends the UIControlEventValueChanged event for handling by the delegate. The delegate can then evaluate the currentPage property to determine the page to display. The page control advances only one page in either direction.

    So you can use that event to determine when a page is changed.

    Example:

    @property (weak, nonatomic) IBOutlet UIPageControl *pageControl;
    @property (strong, nonatomic) NSArray *items;
    

    […]

    - (void)viewDidAppear:(BOOL)animated
    {
        [super viewDidAppear:animated];
        self.items = [NSArray arrayWithObjects:@"One",@"Two",@"Three",@"Four",@"Five",@"Six",@"Seven",@"Eight",@"Nine",@"Ten", nil];
        [self.pageControl addTarget:self action:@selector(pageChanged:) forControlEvents:UIControlEventValueChanged];
    
        // Left Swipe to go to previous page
        UISwipeGestureRecognizer *leftSwipeGestureRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(previousPage:)];
        leftSwipeGestureRecognizer.direction = numberOfTouchesRequired = 1;
        leftSwipeGestureRecognizer.direction = UISwipeGestureRecognizerDirectionLeft;
        [self.view addGestureRecognizer:leftSwipeGestureRecognizer];
    
        // Right Swipe to go to next page
        UISwipeGestureRecognizer *rightSwipeGestureRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(nextPage:)];
        rightSwipeGestureRecognizer.direction = numberOfTouchesRequired = 1;
        rightSwipeGestureRecognizer.direction = UISwipeGestureRecognizerDirectionRight;
        [self.view addGestureRecognizer:rightSwipeGestureRecognizer];
    
    }
    
    - (void)previousPage:(UISwipeGestureRecognizer *)swipeGestureRecognizer
    {
        self.pageControl.currentPage = self.pageControl.currentPage-1;
    }
    
    - (void)nextPage:(UISwipeGestureRecognizer *)swipeGestureRecognizer
    {
        self.pageControl.currentPage = self.pageControl.currentPage+1;
    }
    
    - (void)pageChanged:(id)sender
    {
        NSString *selectedItem = [self.items objectAtIndex:self.pageControl.currentPage];
        NSLog(@"\nSelected Item: %@\nCurrent Page: %d\nTotal Number of Pages: %d\n", selectedItem, self.pageControl.currentPage+1, self.pageControl.numberOfPages);
    }
    

    When you click the page control, it moves forward or backward through the array of strings represented by the self.items property. -pageChanged: is where you would update the controls on the view as well.

    If you want to update the current page in the UIPageControl in another area, simply do:

    self.pageControl.currentPage = 5;  // set to whatever page you need represented
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am interested in using a DataObject and have been looking through the documentation.
I am very interested in using the Passive View pattern to improve testability, but
I'm interested in using Eclipse. The Eclipse Downloads page has versions for Java Developers
I am interested in using a onmouseover event to make a listbox appear and
I'm interested in using a code coverage tool for my next .NET project but
I'm interested in using the WMD editor in another project * but I'm not
I’m interested in using libhid to access a custom HID device that we are
I'm interested in using fcbkcomplete , which has: onselect – fire event on item
My boss is interested in using MKS Integrity for bug tracking, feature requests, Wiki
I'm interested in using Node.js as a socket server for stream-based communication with tens

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.