UITableView不会滚动到某个位置 [英] UITableView won't scroll to certain position

查看:71
本文介绍了UITableView不会滚动到某个位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

[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屋!

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