Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I differentiate source of scrollViewDidScroll call when both UITableView and UIScrollView are present?

Tags:

ios

iphone

ios5

I am using both a UITableView and UIScrollView inside the same UIViewController.

My problem is when I scroll either the table view or scroll view the didScroll delegate call is fired.

How can i identify the source of the scrollViewDidScroll delegate call?

like image 509
iOS Rocks Avatar asked Mar 06 '13 10:03

iOS Rocks


3 Answers

check the scrollView parameter given in the delegate.

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    if(scrollView == self.tableView) {
      // its your tableView
    }
    else if(scrollView == self.scrollView) {
      // its your scrollView
    }
}
like image 70
calimarkus Avatar answered Oct 02 '22 14:10

calimarkus


The didScroll method takes in a scrollview as an input

- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    if(scrollView == self.tableViewInstance){//this is  your table view}
    else {//this is your scroll view}
}

You can check the input and see whether it is your scrollview or tableview which is calling the delegate method.

like image 25
lostInTransit Avatar answered Oct 02 '22 12:10

lostInTransit


You can add tag for UIScrollView as 0 and add tag for UITableView as 1. Inside the delegate check for the tag to know which of this is scrolled and do your stuff:

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
  {
       if(scrollViewl.tag == 0) // ur in scrollView
        if(scrollViewl.tag == 1) // ur in tableView
   }
like image 23
Hossam Ghareeb Avatar answered Oct 02 '22 14:10

Hossam Ghareeb