Question

I have tableview1 and tableview2 in my UIViewController, both of them can be scrolled.

I implement these two methods in the UIViewController but seems when one tableview scrolls the other catches the event as well.

- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
{
    if (!decelerate) {
       // Do something.
    }
}

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
    // Do something.
}

How do I know which tableview is being scrolled so I don't need to run extra code?

Was it helpful?

Solution

UITableView is inherited from UIScrollView, so the (UIScrollView *)scrollView parameter is the pointer to your scrolling tableView

- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
{
    if (scrollView == tableview1 ) {
       // Do something 1.
    }
    else if (scrollView == tableview2 ) {
       // Do something 2.
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top