Remembering state: content offset and table cell reuse
I have a tableview with cells that have a scrollview in them. The scrollview is paged, 2 pages to be exact, and is meant to be able to quickly compare two small blocks of text.
I'm trying to f开发者_如何学编程ind a way to remember what the content offset of the scrollview is. Cell reuse is killing me.
I've tried resetting the offset in prepareForReuse or directly in the cellForRowAtIndexPath, but it seems to give me exactly what you'd expect: Randomly offset tablecells after reuse.
Anyone have any ideas?
If I'm understanding this correctly, you have a scrollview inside each cell that you want to remember the position of. What you need to do is save the content offset along with the text your UITableViewDataSource
is providing and set it in your cellForRowAtIndexPath
method.
Not quite sure if you are trying to remember independent scrolling position, or if you are trying to sync the two tableviews. Assuming the former :
I've not tried this, but if you make each of your tableviews a tableviewcontroller, and add their views to the scrollview, then I would have thought:
1) It would probably just take care of itself
2) you could do your thing in viewWillAppear / viewWillDisapear
Also check this
How can I get the UITableView scroll position so I can save it?
especially Ben's comments.
精彩评论