Iphone UITableViewController使用大表尾滚动过远

Iphone UITableViewController使用大表尾滚动过远,iphone,ios,uitableview,Iphone,Ios,Uitableview,我有一个UITableViewController子类,用于输入应用程序的设置。我通过将自定义按钮添加到我在调用tableView:ViewForFooterInstitution:时返回的视图中,向表页脚添加自定义按钮 - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section { CGRect viewRect = self.view.bounds; flo

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

- (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的横向视图中,它实际上会将编辑文本字段从视图中滚动出去。

您是否实现了
tableView:heightforfooterInstitution
?听起来这可能就是问题所在。如果您实现了
tableView:viewforfooterInstitution
您还必须实现
tableView:heightforfooterInstitution
我怀疑问题在于您实现了键盘上的滚动,但您没有发布任何代码


与其子类化UITableView,不如在执行显示键盘的操作时执行类似于
ScrollToRowatineXpath:atScrollPosition:animated:
的操作?我发现了一个类似的问题。

我解决了这个问题,在我的
tableviewcontroller
中的
tableview
下面添加了一个额外的
UIView
,而不是在我上一个
tableview
部分的页脚中设置一些文本


如果您希望将该页脚分为多个部分,这当然不能解决您的问题。

我发现滚动到rect(即使它来自同一行)似乎可以:

CGRect rect = [myTableView rectForRowAtIndexPath:myIndexPath];
[myTableView scrollRectToVisible:rect animated:YES];

从@ben packard的回答中得到一个提示,我发现
UITableViewController
自动滚动没有故障;实际上是
UITableView
-scrollToRowAtIndexPath:atScrollPosition:animated:
导致视图滚动过远。我必须想象这种行为是故意的,即使它没有文档记录,但在任何情况下,我们都可以通过子类化
UITableView
并重写该方法来修复它:

- (void)scrollToRowAtIndexPath:(NSIndexPath *)indexPath atScrollPosition:(UITableViewScrollPosition)scrollPosition animated:(BOOL)animated {
    if (scrollPosition == UITableViewScrollPositionNone)
        [self scrollRectToVisible:[self rectForRowAtIndexPath:indexPath] animated:animated];
    else
        [super scrollToRowAtIndexPath:indexPath atScrollPosition:scrollPosition animated:animated];
}

我自己不实现任何滚动,因为这是在UITableViewController中自动完成的-请注意,我不是UITableView的子类,而是UITableViewController。这是根据你提到的帖子中Sam Ho的回答完成的。我已经在该线程中尝试了大多数解决方案,但没有成功,这就是为什么我切换到UITableViewController。