Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
485 views
in Technique[技术] by (71.8m points)

iphone - Programmatically force a UIScrollView to stop scrolling, for sharing a table view with multiple data sources

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Did you try these 2 methods?

They actually apply to the "scrolling" not just the offset of the content.

[self.tableView  scrollToRowAtIndexPath:savedIndexPath atScrollPosition:UITableViewScrollPositionTop animated:NO];

OR:

[self.tableView  scrollRectToVisible:savedFrame animated:NO];

They should actually effect the scrolling and by extension the acceleration of the table, not just what is visible on screen.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...