問題描述
我有一個 UITableView,當用戶觸摸分段控件時,它的數據源和委托在幾個自定義數據源對象之間切換(想想應用商店應用中的Top Paid"與Top Free").
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);
這在用戶在表格靜止時切換數據源時效果很好,但是如果用戶在表格仍在移動(即減速)時點擊分段控件,表格視圖會繼續從舊的偏移量開始減速,有效地覆蓋我的 contentOffset 分配.
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.
有沒有辦法在我設置 contentOffset 時強制表格視圖停止滾動/減速,或者有其他方法使這種類型的可切換數據源表格視圖工作?
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?
推薦答案
這2個方法你試過了嗎?
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];
或者:
[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.
這篇關于以編程方式強制 UIScrollView 停止滾動,以便與多個數據源共享表格視圖的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!