Remembering scroll position on UITableView

2019-01-13 15:41发布

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

8条回答
放荡不羁爱自由
2楼-- · 2019-01-13 16:05

As mentioned in other comments, scrolling to the top on Back navigation in a UINavigationController is not the default behavior.

Another cause might be that you are setting a cell near the top of the table as first responder in viewWillAppear, e.g. a search box or edit field near the top of your table. UITableViewController will scroll a first responder into view automatically, which is nice. As long as that's what you're trying to do. :) Take care to not set first responder in viewWillAppear unless that's what you want. Cheers, AZ

查看更多
时光不老,我们不散
3楼-- · 2019-01-13 16:09

You don’t need to do anything, while you are in the same view controller, your position will be the same. I’m afraid that somewhere in your view controller is being called a reloadData. Search for some method calling scrollToRowAtIndexPath.

查看更多
登录 后发表回答