UITableView,页脚留在屏幕底部?

编程入门 行业动态 更新时间:2024-10-28 16:18:44
本文介绍了UITableView,页脚留在屏幕底部?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section { //不同的部分之间或如果你 //只有在部分返回一个静态值 return 49; } - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section { if(footerView == nil){ //如果它还不存在则分配视图 footerView = [[UIView alloc] init]; [footerView addSubview:self.tabBarView]; } //返回页脚的视图 return footerView; }

这是工作可爱,除了当表有少于行为了填充屏幕,这会导致页脚向上移动屏幕,因为表不再创建空行,由于有一个页脚。

因此,有人知道一种方法是将自定义页脚锁定到屏幕底部,或者使tableView创建空行,就像以前一样?

谢谢! p>

Gareth

解决方案

不幸的是,我认为没有一种简单的方法做到这一点,除了一些视图层次化诡计。当UITableView的contentSize小于帧大小时,您将页脚视图分配给self.view并手动定位。当您的UITableView的contentSize大于帧大小时,您使用viewForFooterInSection。让我知道这是不是很清楚,或者如果你想看到一些示例代码如何做到这一点。

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

- (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?

Thanks!

Gareth

解决方案

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,页脚留在屏幕底部?

本文发布于:2023-10-08 04:41:01,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1471539.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:屏幕   UITableView

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!