I have a UITableView whose data source and delegate are switched between a couple of custom data source objects when the user touches a segmented control (think "Top Paid" vs "Top Free" in the app store app).
Each data source object saves its last scroll content offset, and restores it when it becomes the active data source for the table view by doing:
tableView.contentOffset = CGPointMake(0, savedScrollPosition);
This works well when the user switches the data source when the table is at rest, but if the user hits the segmented control while the table is still moving (i.e. decelerating), the table view continues to decelerate from the old offset, effectively overriding my contentOffset assignment.
Is there a way to force the table view to stop scrolling/decelerating when I set the contentOffset, or another way to make this type of switchable-data-source table view work?
I used Corey's approach. I save & restore the rects with the dictionary representation. Also, it may not be obvious but the rect to preserve & restore is the bounds of the UITableView:
Note the interchangeable use of
CFDictionaryRef
andNSDictionary *
Just found this looking for a way to stop my UIScrollView - I needed to move some subviews around, but this wound't look right if the user had flicked the screen and it was still decelerating.
Anyway -
scrollRectToVisible
didn't work for me (maybe because I'm not using a table view??) but this worked perfectly:I can then do the subview stuff without worrying!
Did you try these 2 methods?
They actually apply to the "scrolling" not just the offset of the content.
OR:
They should actually effect the scrolling and by extension the acceleration of the table, not just what is visible on screen.
You could try doing
This might stop the scroll by disabling it, then allow it again. I haven't tried this specifically, but I've done similar things.