记住 UITableView 上的滚动位置 [英] Remembering scroll position on UITableView

查看:26
本文介绍了记住 UITableView 上的滚动位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 iOS 应用在 xcode 中遇到了一些问题.我有一个加载几百个单元格的 UITableView.当我向下滚动到特定单元格并向下钻取到 detailviewcontrollers 并再次返回时,主视图表已返回到顶部.我看过以下两个相似的问题.

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.

我该怎么做获取 UITableView 滚动位置以便我可以保存它?

在 UITableView 中设置滚动位置

我仍然无法让这些工作.我不是最有经验的编码员,所以我真的很挣扎.

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

我知道 viewWillDisappear 和 viewDidAppear 之类的东西需要改变,但我真的不能比这更进一步了.

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

在这张表上,我有一个 reloadData 功能,因此可以从服务器和一个有效的搜索栏下拉最新数据.

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,

卢克

推荐答案

已排序!

从 Desdenova 那里获得了一些灵感,在工作期间,我对它进行了很好的思考并意识到它可能是什么.记得我有一个搜索栏,几个月前我实现了以下代码来隐藏它:

With a bit of inspiration from Desdenova, whilst at work I had a good think about it and realised what it could be. Remembering that I had a search bar, I had implemented the following code a few months ago to hide it:

[self.tableView setContentOffset:CGPointMake(0,-20) animated:NO];

我天真地把它放在 viewDidAppear 而不是 viewDidLoad 中.显然,这确实隐藏了搜索栏,但是由于它在错误的 void 命令中,每次 masterDetailView 返回到堆栈顶部时它都会这样做.所以,在将上面的代码移动到 viewDidLoad 之后,它现在仍然隐藏它,但只是一次.

In naivety I put that in viewDidAppear rather than viewDidLoad. Obviously, this did hide the search bar, but with it being in the wrong void command it did it every time the masterDetailView returned to the top of the stack. So, after moving the above code to viewDidLoad it now still hides it, but only the once.

我只是为其他初学者(例如我自己)这样解释,他们可能会遇到同样的问题,并且可能只是为了挽救他们的理智!

I'm just spelling it out like this for other beginners, like myself, who may come across the same problem and may just save their sanity!

感谢大家的想法帮助了我.

Thanks to you all for your ideas that helped me out.

给大家+1!

这篇关于记住 UITableView 上的滚动位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆