Im making use of this code to align a load of truckDayScrollViews (Subclass of UIScrollView) horizontally in a UITableView, SUDaysForTruckView is just a custom UILabel
-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
if ([scrollView isKindOfClass:[SUDaysForTruckView class]]) {
CGPoint offset=CGPointMake(scrollView.contentOffset.x, 0);
for (TruckViewCell *cell in self.tableView.visibleCells) {
cell.truckDayScrollView.contentOffset=offset;
}
self.headerView.contentOffset=offset;
self.scrollViewPosition=offset;
}
else{
NSLog(@"Table view scrolling vertically: %f,%f",self.scrollViewPosition.x,self.scrollViewPosition.y);
self.headerView.contentOffset=self.scrollViewPosition;
}
}
The idea being, that if the class of the scrolling scroll view is part of the cell (scrolling horizontally) then update all the scrollviews, including the header. This works great.
Although when the tableView scrolls vertically, the content offset in the header scroll view is reset to 0,0.
Why is this, and is there a way to fix it. I have tried putting the line
self.headerView.contentOffset=self.scrollViewPosition;
in so many places cellForRow, the getter for self.headerView,etc. all to no avail.
The first picture shows horizontal scrolling and how the header is aligned, the second picture shows what happens on the very first bit of vertical scrolling, the headers jump out of alignment immediately.