UITableView,页脚留在屏幕底部? [英] UITableView, make footer stay at bottom of screen?

查看:208
本文介绍了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,页脚留在屏幕底部?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆