Search code examples
iosnslog

iOS - how to NSLog just one time when using scrollViewDidScroll


In the method - (void)scrollViewDidScroll:(UIScrollView *)sender I tried to NSLogan integer and it NSLog the integer more than one time when I scroll.

Is there's any way to NSLog the integer just one time?


Solution

  • Use the UIScrollViewDelegate method scrollViewWillBeginDragging: to get only when the scroll starts. It is not called constantly like scrollViewDidScroll: is.

    Here are the other UIScrollViewDelegate methods if you are interested:

    – scrollViewDidScroll:
    – scrollViewWillBeginDragging:
    – scrollViewWillEndDragging:withVelocity:targetContentOffset:
    – scrollViewDidEndDragging:willDecelerate:
    – scrollViewShouldScrollToTop:
    – scrollViewDidScrollToTop:
    – scrollViewWillBeginDecelerating:
    – scrollViewDidEndDecelerating:
    

    Source: https://developer.apple.com/library/ios/documentation/uikit/reference/uiscrollviewdelegate_protocol/reference/uiscrollviewdelegate.html#//apple_ref/occ/intfm/UIScrollViewDelegate/scrollViewWillBeginDragging: