ealeksandrov/EAIntroView

Delegate method pageAppeared doesn't being called

aleufms opened this issue · 3 comments

The method func intro(introView: EAIntroView!, pageAppeared page: EAIntroPage!, withIndex pageIndex: UInt) doesn't being called when we use the funcion setCurrentPageIndex:animated

This is because the method setCurrentPageIndex:animated: sets self.currentPageIndex before scrolling:

    _currentPageIndex = currentPageIndex;

And then, in the scrollViewDidEndScrollingAnimation: delegate method, it calls the following code:

    [self notifyDelegateWithPreviousPage:self.currentPageIndex andCurrentPage:newPageIndex];
    _currentPageIndex = newPageIndex;

This notifyDelegate method has a check:

    if(currentPageIndex!=_currentPageIndex && currentPageIndex < _pages.count) {
        [call delegate]

Because the setCurrentPageIndex:animated method already set the _currentPageIndex ivar, this notifyDelegate check fails.

In general, I would recommend against custom setters that have side-effects. So we would have a (mostly empty) setter for setCurrentPageIndex:, and a separate method that performs the scrolling (like scrollToPageIndex:).

I'm able to reproduce this as well by using tapToNext and tapping on the pages.

Okay, I fixed this in #177 . You can call scrollToPageForIndex:animated: to switch pages, and it should hit the delegate method.