UITableView,让页脚停留在屏幕的底部?

Gar*_*nne 25 iphone cocoa-touch objective-c

我有一个带页脚的UITableView,在自定义视图中填充了tabBar,使用以下代码完成:

- (CGFloat)tableView:(UITableView *)tableView
heightForFooterInSection:(NSInteger)section {
    //differ between your sections or if you
    //have only on section return a static value
    return 49;
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {

    if(footerView == nil) {
        //allocate the view if it doesn't exist yet
        footerView  = [[UIView alloc] init];
        [footerView addSubview:self.tabBarView];
    }

    //return the view for the footer
    return footerView;
}
Run Code Online (Sandbox Code Playgroud)

哪个工作很可爱,除了当桌子的行数少于填充屏幕所需的行数时,这会导致页脚向上移动,因为桌子不再创建空行,因为有一个页脚.

那么,有没有人知道如何将自定义页脚锁定到屏幕底部,或者,使tableView像以前一样创建空行?

谢谢!

加雷思

Dan*_*maa 4

不幸的是,除了一些视图层次结构技巧之外,我认为没有一种简单的方法可以做到这一点。当 UITableView 的 contentSize 小于框架大小时,您将页脚视图分配给 self.view 并手动定位。当 UITableView 的 contentSize 大于框架大小时,您可以使用 viewForFooterInSection。如果不清楚或者您想查看一些有关如何执行此操作的示例代码,请告诉我。