UITableView 不会滚动到某个位置

发布于 2024-09-19 01:33:34 字数 192 浏览 2 评论 0原文

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

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

有谁知道怎么回事吗?

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

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.

Anyone know whats up?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

空宴 2024-09-26 01:33:34

要设置节标题的 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;
}

为我工作,希望对其他人也如此。

To set the UIView for the section header, you're using function:

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

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.

如何视而不见 2024-09-26 01:33:34

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


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

这将使 tableView 从 yPos 48 开始。

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

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

You can try the method named -scrollRectToVisible:animated.


I misunderstand your question. So, what you want is to initialize the tableview with a shift of y-coordinate about 48 pixels ?

This will make the tableView begin from yPos 48.

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

Hope this can help you....

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文