My solution was this:
Add a IBAction in your header:
- (IBAction)changePage;
Dont forget to set the Outlet and the property for the pageControl:
IBOutlet UIPageControl *pageControl;
@property (nonatomic, retain) IBOutlet UIPageControl* pageControl;
Add a BOOLEAN that the pagecontrol updates:
BOOL pageControlBeingUsed;
Here is my full header:
@interface ViewC : UIViewController <UIScrollViewDelegate> {
IBOutlet UIScrollView *scrollView;
IBOutlet UIPageControl *pageControl;
BOOL pageControlBeingUsed;
}
@property (nonatomic, retain) IBOutlet UIScrollView* scrollView;
@property (nonatomic, retain) IBOutlet UIPageControl* pageControl;
- (IBAction)changePage;
@end
(Don't forget to synthesize the propertys) The second step you did already with the viewdidLoad method but you didn't connected the Boolean to the method! Try this:
- (void)scrollViewDidScroll:(UIScrollView *)sender {
if (!pageControlBeingUsed) {
// Switch the indicator when more than 50% of the previous/next page is visible
CGFloat pageWidth = self.scrollView.frame.size.width;
int page = floor((self.scrollView.contentOffset.x - pageWidth / 2) / pageWidth) + 1;
self.pageControl.currentPage = page;
}
}
Add at the end this code for the IBAction and that when the pageControl was pressed at a button the site changes.
- (IBAction)changePage {
// update the scroll view to the appropriate page
CGRect frame;
frame.origin.x = self.scrollView.frame.size.width * self.pageControl.currentPage;
frame.origin.y = 0;
frame.size = self.scrollView.frame.size;
[self.scrollView scrollRectToVisible:frame animated:YES];
pageControlBeingUsed = YES;
}
IMPORTANT: Connect the IBAction with "value changed" option in the xib. and set the delegate of the Controller to itself:
And then it should be like this:
That is all! Hope you fixed your issue. I would be glad if you give my awnser the "tick" if it helped you!
Greetings,
Noah