Victor C.
Victor C.

Reputation: 191

UITableView in UIView in UIScrollView. When scrolling tableview don't scroll scrollview too

I have a UITableView inside a UIView inside a UIScrollView. Problem: when i scroll/drag the tableview, the scrollview scrolls too.
What i need is for the tableview not to pass the scroll to the scrollview. Also i need to be able to use the scrollview when i scroll it directly. How can i do this? Cheers

enter image description here

Upvotes: 3

Views: 1815

Answers (2)

Victor C.
Victor C.

Reputation: 191

I fixed it using "hitTest" on the tableview.

 - (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event

If the event originated within the tableview, i disable the parent's scrollview scroll. And, when the tableview's scroll has ended (scrollViewDidEndDragging) i re-enable the parent's scrollview scroll.

This seams to work fine.

Upvotes: 1

Set a delegate to your tableview's scrollview (i.e your view controller)

tableView.scrollView.delegate = self;

then use those two calls

– scrollViewDidScroll:
– scrollViewDidEndDragging:willDecelerate:

to disable and re-enable your outside scrollview's scrollEnabled property

Upvotes: 0

Related Questions