UITableViewController使用大型页脚滚动太远

时间:2011-08-28 17:36:53

标签: iphone ios uitableview

我有一个UITableViewController子类用于输入我的应用程序的设置。我通过将自定义按钮添加到我在调用tableView时返回的视图中添加自定义按钮:viewForFooterInSection:。

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section 
{
    CGRect viewRect = self.view.bounds;
    float height = _settings.isNew ? 50.0 : 110.0;
    float margin = (viewRect.size.width > 480.0) ? 44.0 : 10.0; 
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, viewRect.size.width, height)];    

    GradientButton* button = [[GradientButton alloc] initWithFrame:CGRectMake(margin, 5, viewRect.size.width - margin * 2, 44)];
    [view addSubview:button];
    [button addTarget:self action:@selector(testConnectionClicked:) forControlEvents:UIControlEventTouchUpInside];
    [button release];

    if (!_settings.isNew)
    {
    // I add another button
    }

    return [view autorelease];
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section 
{
    return _settings.isNew ? 50 : 110;
}

从UITableViewController进行子类化的重点是避免在键盘出现时将单元格滚动到视图中的问题。

这主要是应该的,但是当编辑移动到最后一个单元格时,它似乎试图将表格页脚滚动到视图中。这意味着它在横向视图中在iPhone上实际滚动编辑文本域。

5 个答案:

答案 0 :(得分:2)

我通过在UIView的{​​{1}}下方添加额外tableview而不是在我上一个tableviewcontroller部分的页脚中设置一些文字来解决此问题。

如果您想在多个部分中使用该页脚,那么这当然不会解决您的问题。

答案 1 :(得分:1)

从@ ben-packard的回答中得到一个提示,我发现UITableViewController自动滚动没有错;它实际上是UITableView的{​​{1}},导致视图滚动太远。我必须想象这种行为是有意的,即使它没有记录,但无论如何我们可以通过继承-scrollToRowAtIndexPath:atScrollPosition:animated:并重写该方法来修复它:

UITableView

答案 2 :(得分:0)

您是否实施了tableView:heightForFooterInSection?听起来这可能是问题所在。如果您实施tableView:viewForFooterInSection,则还必须实施tableView:heightForFooterInSection

答案 3 :(得分:0)

我怀疑问题在于你在键盘上滚动的实现,但你没有发布任何代码。

当您执行显示键盘的操作时,为什么不执行scrollToRowAtIndexPath:atScrollPosition:animated:之类的操作,而不是为UITableView创建子类?我找到了类似的thread here

答案 4 :(得分:0)

我发现滚动到矩形(即使它是从同一行派生的)似乎有效:

CGRect rect = [myTableView rectForRowAtIndexPath:myIndexPath];
[myTableView scrollRectToVisible:rect animated:YES];
相关问题