User User - 1 year ago 158
Objective-C Question

How to click button and move on next page?

I have

I want to scroll in next page on button click but my code doesn’t work.
When I press on button once I move to next page but when press again I move in the end page. How to click button and move on next page?

int i;
i = i+1;

[scroller setContentOffset:CGPointMake(scroller.frame.size.width*i, 0) animated:YES];

Answer Source

The problem is that int i is defined everytime when you fire aMethod:.

You should define @property (nonatomic, assign) NSInteger currentPageIndex; in your class' interface and increment it when invoke aMethod:

- (IBAction)nextPageButtonTapped:(id)sender {
    CGFloat pageWidth = scroller.frame.size.width;
    [scroller setContentOffset:CGPointMake(pageWidth*self.currentPageIndex, 0) animated:YES];
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download