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
246 views
in Technique[技术] by (71.8m points)

ios - Remembering scroll position on UITableView

I have a bit of a problem with my iOS app in xcode. I have a UITableView that loads a few hundred cells. When I scroll down to a specific cell and drill down to detailedviewcontrollers and return again the master view table has returned all the way to the top. I've had a look at the following 2 questions that are similar.

How can I get the UITableView scroll position so I can save it?

Setting scroll position in UITableView

I still can't get these to work. I'm not the most experienced coder so I'm really struggling with this.

I know things like viewWillDisappear and viewDidAppear need to be changed, but I just really can't get much further than that.

On this table I have a reloadData feature so it is possible to pull down the latest data from the server and also a working search bar.

Anyway, a helping hand would be great. Thanks,

Luke

See Question&Answers more detail:os

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

1 Reply

0 votes
by (71.8m points)

See here you have to first save the scrolled position of tableView i.e. contentOffset of tableView and then reuse it when you are coming back to tableView.

1)When and where you will save it :

When : At the point, when you are drilling down to detailViewController save the contentOffset of tableView

How : float verticalContentOffset = tableView.contentOffset.y;

2) How will you set tableView back to the same scrolled position :

[tableView setContentOffset:CGPointMake(0, verticalContentOffset)];

Hope this will help you.


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

...