繁体   English   中英

UITableView不会滚动到某个位置

[英]UITableView won't scroll to certain position

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

我有一个UITableView在标题中有一个UIView。 我的UITableView不会滚动到(0,48),除非动画:是。 我不希望它有动画。

有谁知道什么?

您可以尝试名为-scrollRectToVisible:animated的方法。


我误解了你的问题。 那么,你想要的是用y坐标移动约48像素初始化tableview?

这将使tableView从yPos 48开始。

tableView.contentInset = UIEdgeInsetsMake(48, 0.0, 0.0, 0.0);

希望这可以帮到你....

要为节标题设置UIView,您正在使用函数:

- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section; 

我怀疑你在viewWillAppear中的某处调用setContentOffset,但稍后会调用该函数。 我认为它会覆盖你的contentOffset。 ...不确定为什么它在动画为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;
}

为我工作,希望其他人也这样做。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM