objective-c UITableView,让页脚停留在屏幕底部?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18047720/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 20:54:53  来源:igfitidea点击:

UITableView, make footer stay at bottom of screen?

iphoneobjective-ccocoa-touch

提问by Gareth Jeanne

I have a UITableView with a footer, filled with a tabBar in a custom view, done using the following code:

我有一个带有页脚的 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;
}

Which is working lovely, apart from when the table has less rows than are needed to fill the screen, this causes the footer to move up the screen, as the table no longer creates empty rows, due to having a footer.

除了当表格的行数少于填充屏幕所需的行数时,这工作得很好,这会导致页脚在屏幕上移动,因为表格不再创建空行,因为有页脚。

So, does anyone know of a way to either lock the custom footer to the bottom of the screen, or, to make the tableView create empty rows as it used to do?

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

Thanks!

谢谢!

Gareth

加雷斯

回答by Dany Joumaa

Unfortunately I don't think there is an easy way to do this, other than some view hierarchy trickery. When the contentSize of your UITableView is less than the frame size, you assign the footer view to self.view and position manually. When the contentSize of your UITableView is greater than the frame size, you use viewForFooterInSection. Let me know if this isn't clear or if you'd like to see some sample code on how to do this.

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

回答by g212gs

I have the same problem for uitableview controller, I solved this by adding view in the window and remove this object in viewWillDisappear.

我对 uitableview 控制器有同样的问题,我通过在窗口中添加视图并在 viewWillDisappear 中删除这个对象来解决这个问题。

My Solution link

我的解决方案链接