views:

1080

answers:

5

I have a UITableView instance variable. I want to be able to register my view controller to be the UIScrollViewDelegate for my UITableView controller. I have already tried

tableView.delegate = self;

But when scrolling, my methods

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView            
                  willDecelerate:(BOOL)decelerate

don't get called. Any suggestions?

A: 

try

[[tableView scrollView] setDelegate:self];

You may get a warning that says tableView doesn't respond to scrollView, but it might work?

Jasarien
UITableView is a descendant of UIScrollView.Found some code to handle putting a UIWebView in a table cell on http://gist.github.com/100277 which uses some tricks you probably don't need, but might be interested in.
Epsilon Prime
I got an error saying that my table view does not respond to scrollView. Good try though.
Brian
+3  A: 

This is officially unsupported. UITableView and UIWebView do not expose their internally managed scrollviews.

You can descend into the subview hierarchy and make undocumented calls, but that's not recommended, as it's officially prohibited and can break under future OS versions if the underlying (undocumented) API changes.

Marco
I was afraid this was the case. Thanks.
Brian
As santoni's answer below indicates, `UITableViewDelegate` conforms to `UIScrollViewDelegate` (this may have changed in an SDK release?), which means that all `UIScrollViewDelegate` messages will get passed to the `UITableView`'s delegate.
Nick Forge
A: 

for(int i=0;i<[[tableView subviews]count];i++){ if ([[[tableView subviews]objectAtIndex:i]isKindOfClass:[UIScrollView class]]) { [[[tableView subviews]objectAtIndex:i]setDelegate:self]; } }

Iain
+6  A: 

Now UITableViewDelegate conforms to UIScrollViewDelegate !

(I write this answer because many people are going to find this page googling..)

F.Santoni
You were so right!
Nava Carmon
A: 

UITableDelegate will implement UIScrollViewDelegate also.

Karthik Thirumalasetti