Iphone:如何滚动到第二部分的第一个单元格,让第一部分的标题可见
我有一个包含行和部分的 UITableView。 我想滚动到第二部分的第一项,让第一部分的标题可见。就像我手动滚动列表直到达到该状态一样。
---- TOP OF SCREEN ----
Header of first section
Header of the second section
cell 1
cell 2
cell 3
Header of the third section
cell 1
cell 2
...
scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:1] 不做这项工作,它隐藏了第一部分的标题。
I have an UITableView with rows and sections.
I would like to scroll to the first item of the second section, letting the header of the first section visible. Like if I had manually scrolled the list until reaching that state.
---- TOP OF SCREEN ----
Header of first section
Header of the second section
cell 1
cell 2
cell 3
Header of the third section
cell 1
cell 2
...
scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:1]
does not do the job, it hides the header of the first section.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我们继续前进。我根据Kevin的想法找到了这个方法。为了能够将动画设置为 YES,我使用 UIScrollView 的委托方法捕获动画的结束。有用。但任何有助于不做两个动画的解决方案将不胜感激。 知道如何做到这一点吗?
由于这段代码,动画设置为YES时的过程应该在scrollViewDidEndScrollingAnimation和showFirstHeaderLine之间无限循环...它循环,是的,但只循环一次...<强>知道为什么吗?
We're moving on. I found this method based on Kevin's idea. To be able to set animated to YES, I catch the end of animation using a delegate method of UIScrollView. It works. But any solution that would help not doing 2 animations would be greatly appreciated. Any idea about how to do this ?
Dude to this code, the process when animated is set to YES should loop infinitely beetween scrollViewDidEndScrollingAnimation and showFirstHeaderLine... It loops, yes, but only once... Any idea about why ?
您可以抓取所需行的矩形,然后减去上一节标题的高度并滚动到该点。类似以下内容(未经测试)应该有效:
You can grab the rect for the row you want, then subtract the height of the header of the previous section and scroll to that point. Something like the following (untested) should work:
我尝试了你的代码,它有效!
对于循环问题,由于您设置的是偏移量(SetContentOffset),因此它与滚动无关。它不会调用scrollView委托。因此,scrollViewDidEndScrollingAnimation 只会被调用一次,这是从scrollToRowAtIndexPath 调用的。
I tried your code, and it works!!
For the loop question, since you are setting a offset(SetContentOffset), it has nothing to do with the scroll. It is will not call scrollView delegate. SO the scrollViewDidEndScrollingAnimation will be called only once, which has been called from scrollToRowAtIndexPath.