In my app, I have two tableViews side by side. When the user scrolls on, I would like the second one to scroll at the same time, so it looks almost like one table with two different columns. I'm a bit lost on how to go about doing this, any suggestions?
Thanks, Greg
UITableView is a subclass of UIScrollView. Swift solution:
And stop the bounce of both the tables
If you want to make vertical scroll Indicators go, write the below code
in swift scroll two uitableviews symmetrically:
also, the tableview that got scrolled by the user should not be sent setContentOffset: message in scrollViewDidScroll, since it will get the app into endless cycle. so additional UIScrollViewDelegate methods should be implemented in order to solve the problem:
and modifying Inspire48's version scrollViewDidScroll: accordingly:
where beingScrolled_ is an ivar of type UIScrollView
You'll want to look into the
UIScrollViewDelegate
- say you've got two scroll views, A and B.Use the
scrollViewDidScroll
delegate method of scroll view A to get the offset, and then in the same method callsetContentOffset
on scroll view B, passing in the value you get from the delegate.It actually shouldn't be more than 2-3 lines of code once you've set-up your delegate methods.
Conveniently, UITableView is a subclass of UIScrollView. There exists a UIScrollViewDelegate, which has this method:
If you implement that method, you can get the
contentOffset
property of thescrollView
argument. Then, you should useand set the new content offset. So something like this:
You can cast to a UITableView if you'd like, but there's no particular reason to do so.