UIPageControl value changed without firing

I have a problem with UIPageControl . I simplified the problem for clarity below:

I put the button and UIPageControl into my application using the interface builder and put the following in the code:

 - (IBAction)tappedButton:(id)sender{ self.pageControl.currentPage = 3; NSLog(@"Tapped Button"); } - (IBAction)changePage:(id)sender{ NSLog(@"PAGE Changed!!!!"); } 

I applied the Value Changed action to the Controller page through the interface builder.

When I click on the button, I see the output of "Tapped Button", and the third point is highlighted ... but the changePage method changePage never called.

Any ideas?

+4
source share
2 answers

The changePage: method will only be called when users request a page change using UIPageControl. It will not be called when the user clicks a button. If you want to call the changePage: method when the button is pressed, it is called explicitly:

  [self changePage: nil]; 
+2
source

UIPageControl does not actually change the page for you. You must write this code in response to the valueChanged event. So you want to associate this event of your UIPageControl object with your output ( tappedButton: I think), and then call your changePage: method to actually change the user interface. Does it help?

There are several sample projects referenced by Apple docs that use UIScrollView and UIPageControl together. Check them out.

+1
source

All Articles