[英]UITableView won't scroll to certain position
[self.tableView setContentOffset:CGPointMake(0,48) animated:NO];
I have a UITableView that has aa UIView in the header. 我有一个UITableView在标题中有一个UIView。 My UITableView won't scroll to (0,48) unless animated: YES.
我的UITableView不会滚动到(0,48),除非动画:是。 I don't want it to animate.
我不希望它有动画。
Anyone know whats up? 有谁知道什么?
You can try the method named -scrollRectToVisible:animated . 您可以尝试名为-scrollRectToVisible:animated的方法。
I misunderstand your question. 我误解了你的问题。 So, what you want is to initialize the tableview with a shift of y-coordinate about 48 pixels ?
那么,你想要的是用y坐标移动约48像素初始化tableview?
This will make the tableView begin from yPos 48. 这将使tableView从yPos 48开始。
tableView.contentInset = UIEdgeInsetsMake(48, 0.0, 0.0, 0.0);
Hope this can help you.... 希望这可以帮到你....
To set the UIView for the section header, you're using function: 要为节标题设置UIView,您正在使用函数:
- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section;
I suspect you invoke setContentOffset somewhere in viewWillAppear, but that function is called later. 我怀疑你在viewWillAppear中的某处调用setContentOffset,但稍后会调用该函数。 And I think it overwrites your contentOffset.
我认为它会覆盖你的contentOffset。 ...not sure why it doesn't when animated is YES, but anyway, just put your setContentOffset into this function like this:
...不确定为什么它在动画为YES时不会,但无论如何,只需将setContentOffset放入此函数中,如下所示:
- (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. 为我工作,希望其他人也这样做。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.