IPhone - how to scroll two UITableViews symmetrically?

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 call setContentOffset 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.

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 call setContentOffset 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.

Cool, I'll go give that a shot right now :) – Greg Aug 4 at 22:13 Yeah, works beautifully :) thanks! I would vote up, but I don't have 15 rep points XD – Greg Aug 4 at 22:22.

Conveniently, UITableView is a subclass of UIScrollView. There exists a UIScrollViewDelegate, which has this method: - (void)scrollViewDidScroll:(UIScrollView *)scrollView If you implement that method, you can get the contentOffset property of the scrollView argument. Then, you should use - (void)setContentOffset:(CGPoint)contentOffset animated:(BOOL)animated and set the new content offset.So something like this: - (void)scrollViewDidScroll:(UIScrollView *)scrollView { UIScrollView *otherScrollView = (scrollView == self.

TableView1)? Self. TableView2 : self.

TableView1; otherScrollView setContentOffset:scrollView contentOffset animated:NO; } You can cast to a UITableView if you'd like, but there's no particular reason to do so.

I'd say its semantically better to cast as a UITableView, and is good for readability. Programmatically in this case though, it doesn't matter – Benjamin Mayo Aug 4 at 22:18 Good point…I'm used to setting these methods animated. Changed.

– Inspire48 Aug 4 at 23:19.

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: - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView { beingScrolled_ = nil; } - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView { if(beingScrolled_ == nil) beingScrolled_ = scrollView; } and modifying Inspire48's version scrollViewDidScroll: accordingly: - (void)scrollViewDidScroll:(UIScrollView *)scrollView { UIScrollView *otherScrollView = (scrollView == self. TableView1)?Self.

TableView2 : self. TableView1; if(otherScrollView! = beingScrolled) { otherScrollView setContentOffset:scrollView contentOffset animated:NO; } } where beingScrolled_ is an ivar of type UIScrollView.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions