Iphone:如何滚动到第二部分的第一单元格,使第一部分的标题可见 [英] Iphone : How to scroll to the 1st cell of the 2nd section, letting the header of the 1st section visible

查看:61
本文介绍了Iphone:如何滚动到第二部分的第一单元格,使第一部分的标题可见的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有行和节的UITableView. 我想滚动到第二部分的第一项,以使第一部分的标题可见.就像我手动滚动列表直到到达该状态一样.

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] 没有完成这项工作,而是隐藏了第一部分的标题.

scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:1] does not do the job, it hides the header of the first section.

推荐答案

我们在继续.我是根据Kevin的想法找到这种方法的.为了能够将动画设置为YES,我使用UIScrollView的委托方法捕获了动画的结尾.有用.但是任何不做2个动画的解决方案将不胜感激. 关于如何执行此操作的任何想法?

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 ?

- (IBAction) scrollToToday:(BOOL)animate {
    [self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:1] atScrollPosition:UITableViewScrollPositionTop animated:animate];
    if (animate == NO) [self showFirstHeaderLine:NO];
}

- (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView {
    [self showFirstHeaderLine:YES];
}

- (void) showFirstHeaderLine:(BOOL)animate {
    CGRect headerRect = [self.tableView rectForHeaderInSection:1];
    CGPoint scrollPoint = headerRect.origin;
    scrollPoint.y -= headerRect.size.height;
    [self.tableView setContentOffset:scrollPoint animated:animate];
}

使用此代码,动画设置为YES的过程应该在scrollViewDidEndScrollingAnimation和showFirstHeaderLine之间无限循环...它循环,是的,但是只有一次... 关于为什么的任何想法?

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 ?

这篇关于Iphone:如何滚动到第二部分的第一单元格,使第一部分的标题可见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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