views:

50

answers:

1

I have 2 UITableViews on my screen.

As the user scrolls 1... I need the other 1 to also scroll to the same row.

I assume I need to find a "tableViewDidScroll" method... and somehow detect a "whichRowIsDisplayed" value... and then set the other tableView to "displayThisSameRow".

I can't find any of those 3 methods that I need.

Help!

(Edit: both tables always will have the same number of rows)

A: 

If the rows in your tables are the same height, you can use the UIScrollView methods to set the contentOffset directly.

Implement the delegate method scrollViewDidScroll: for both tables. Whichever table made the call, set the contentOffset of the other table to match. You should track when you are setting the offset to avoid unnecessary calls.

// table1, table2, tableBeingScrolled all members
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
  if ( scrollView != tableBeingScrolled ) {
    if ( scrollView == table1 ) {
      tableBeingScrolled = table2;
      table2.contentOffset = table1.contentOffset;
      tableBeingScrolled = nil;
    }
    if ( scrollView == table2 ) {
      tableBeingScrolled = table1;
      table1.contentOffset = table2.contentOffset;
      tableBeingScrolled = nil;
    }
  }
}

If the tables have different row heights, you could use the same technique but would need more calculations to figure out what offset to assign.

drawnonward
> You should track when you are setting the offset to avoid unnecessary calls. < I assume that's where the "tableBeingScrolled" comes into use. Where would be a good place to define that variable?Thanks... it seems to be working now!
Susanna