UITableView不会滚动到特定位置 [英] UITableView won't scroll to certain position
问题描述
[self.tableView setContentOffset:CGPointMake(0,48) animated:NO];
我有一个UITableView,它的标题中有一个UIView.除非启用动画,否则我的UITableView不会滚动到(0,48).我不想让它动起来.
I have a UITableView that has a a UIView in the header. My UITableView won't scroll to (0,48) unless animated: YES. I don't want it to animate.
有人知道怎么回事吗?
推荐答案
要设置节标题的UIView,请使用以下函数:
To set the UIView for the section header, you're using function:
- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section;
我怀疑您在viewWillAppear中的某处调用了setContentOffset,但是稍后会调用该函数.而且我认为它会覆盖您的contentOffset. ...不确定动画设置为YES时为什么不显示,但是无论如何,只需将setContentOffset放入此函数中即可,如下所示:
I suspect you invoke setContentOffset somewhere in viewWillAppear, but that function is called later. And I think it overwrites your contentOffset. ...not sure why it doesn't when animated is YES, but anyway, just put your setContentOffset into this function like this:
- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIView *headerView = nil;
if (section == SEC_WITH_IMAGE_HEADER) {
headerView = self.neededView;
}
[self.tableView setContentOffset:CGPointMake(0,48) animated:NO];
return headerView;
}
为我工作,希望对其他人也如此.
Worked for me, hope so will for somebody else.
这篇关于UITableView不会滚动到特定位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!