Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CCScrollLayer doesn't call delegate method when [scrollLayer selectPage:1]; #93

Open
draganjovev opened this issue Dec 8, 2011 · 3 comments

Comments

@draganjovev
Copy link

Steps to reproduce issue

scrollLayer = [[CCScrollLayer alloc] initWithLayers:someLayers
widthOffset:0];
[scrollLayer selectPage:1];
[scrollLayer setDelegate:self];
[self addChild:scrollLayer];

  • (void) scrollLayer: (CCScrollLayer *) sender scrolledToPageNumber: (int) page {
    NSLog(@"Delegate called");
    }

Since you're on page 1, try to go to page 0 and you will see that delegate method is not called because currentScreen_ and prevScreen_ are equal.

Solution si to replace line 119 to

currentScreen_ = NSNotFound;

@liamoreilly
Copy link

I can confirm this bug. Although the line number in the previous post has changed with the current version.

@liamoreilly
Copy link

To Clarify. draganjovev is correct, but I disagree with his solution. His solution results in the following odd behaviour. If you setup the use case as he describes and slightly try to scroll (but make sure the page lands on the same one - i.e. no actual change page occurs) then the delegate gets fired when it should not get fired.

I propose that the solution is to swap lines 291 and 292 in -(void) selectPage:(int)page. That was the current page and previous page are recorded as the same when you use this method. If you then manually change page the delegate gets fired, but it you happen to nudge the page and it moves back to center (no page change really occurred), then the delegate wont get fired.

For completeness the method now looks like:

-(void) selectPage:(int)page
{
    if (page < 0 || page >= [layers_ count]) {
        CCLOGERROR(@"CCScrollLayer#selectPage: %d - wrong page number, out of bounds. ", page);
        return;
    }

    self.position = [self positionForPageWithNumber: page];

    // Original:
    // prevScreen_ = currentScreen_;
    // currentScreen_ = page;

    // My solution:
    currentScreen_ = page;
    prevScreen_ = currentScreen_;   
}

@KerryBatts
Copy link

I tested and confirmed the bug and also aliam13's fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants