ealeksandrov / EAIntroView

Highly customizable drop-in solution for introduction views.
MIT License
3.76k stars 501 forks source link

Delegate method pageAppeared doesn't being called #174

Closed aleufms closed 8 years ago

aleufms commented 8 years ago

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

JakeSc commented 8 years ago

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:).

JakeSc commented 8 years ago

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

JakeSc commented 8 years ago

Okay, I fixed this in https://github.com/ealeksandrov/EAIntroView/pull/177 . You can call scrollToPageForIndex:animated: to switch pages, and it should hit the delegate method.