4
votes

I'm working on a project where I have to work lot of with UITableViews. So, I want to detect if the table view (UIScrollView) is scrolling.

First I handled it with the UIScrollViewDelegate in the UIViewController where my UITableView is added as a subview. Now, to keep the code clean, I want to subclass UITableView and in this class I have to access to the delegate methods of UIScrollView, e.g. - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView.

But how can I do this? Is it possible?

2

2 Answers

4
votes

All you have to do is implement - (void)scrollViewDidScroll:(UIScrollView *)scrollView delegate & detect if the scrolling is happening in your UITableView or somewhere else.

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    if(scrollView == self.tableView)
    {
        //your logic here
    }
    return;
}
2
votes

Those UIScrollViewDelegate methods must be defined in a class that is the delegate of the tableview that you want to handle scrolling changes of. If you put these methods in the implementation file of your UITableView subclass then you should set the tableview's delegate as itself:

[self setDelegate:self];

But then you also have to define your UITableViewDelegate and UITableViewDataSource methods in the UITableView subclass. This might complicate things if you want to use your UITableView subclass more than one place in your project. If I were you, I would double-think about my design and behave accordingly.