Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why UITableView calls UIScrollView's delegate methods?

I have an application, in which I have a UITableView inside a UIView, which is again inside a UIScrollView, so the hierarchy becomes like this:

UIScrollView -> UIView -> UITableView

The data inside my UITableView is filled properly.

Now, my problem is that, When I scroll my UITableView, the UIScrollView's delegate method scrollViewDidEndDecelerating: and scrollViewDidEndDragging:: gets called.

I don't want this behavior, what should I do to stop this behavior?

Any one please Help, Thank in advance!!!

like image 232
Kanan Vora Avatar asked Jul 10 '12 10:07

Kanan Vora


People also ask

What is UITableView delegate?

Methods for managing selections, configuring section headers and footers, deleting and reordering cells, and performing other actions in a table view.

Which delegate method must be implemented to provide the cell of each row in a UITableView?

Delegate Methods in UITableView. willDisplay: This method gets called when the table view cell is going to display on the screen. willDisplayHeaderView: This method gets called when the header view of the section will be display.

What is table View delegate and datasource?

Datasource methods are used to generate tableView cells,header and footer before they are displaying.. Delegate methods provide information about these cells, header and footer along with other user action handlers like cell selection and edit..


2 Answers

UITableViewDelegate extends UIScrollViewDelegate. Hence the calling of the delegate methods.

To stop this you can set tableView.tag = 1000; when you alloc the tableView and in the UIScrollViewDelegate methods ( scrollViewDidEndDecelerating: and scrollViewDidEndDragging:: )add this at the very begining:

if(scrollView.tag == 1000)
    return;
like image 57
George Avatar answered Oct 13 '22 19:10

George


Because UITableView inherits from UIScrollView. So it shows all the properties and behaviours of UIScrollView. If you dont want this then please do one thing.

Assuming you have another scrollview in your page.

in the viewDidLoad or from the XIB (if you have your tableview in the XIB), set a tag for your tableview.

in code,

self.objYourTableView.tag = 101;

then in the scroll view delegate

- (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView
  {
       if(!(scrollView.tag == 101))
       {
          // Go for your code to run.
       }
  }

So that your code will skip if it called by the table view. Other cases it works perfect. Hope this will help you.

like image 21
Mathew Varghese Avatar answered Oct 13 '22 18:10

Mathew Varghese