Search code examples
iosobjective-cuiviewuiscrollviewuiscrollviewdelegate

How to call UIScrollView's delegate method when there are two scrollViews in the UIViewController


When there're two scrollViews in the UIViewController, how can I call UIScrollView's delegate method, which makes it only works on one of scrollViews and never affects the another?


Solution

  • Since your question is not that clear, if you only want to manage one of the UIScrollViewDelegate, don't set the scrollView2.delegate of the unwanted one.

    If you want to different ways of manage of the delegates, here's what you can do, with the example of scrollViewDidScroll: method. Usually, delegates method always give as a parameter the "delegated" object.

    - (void)scrollViewDidScroll:(UIScrollView *)scrollView
    {
        if (scrollView == yourScrollView1)
        {
            //Do something
        }
        else //if (scrollView == yourScrollView2)
        {
            //Do something
        }
    }