TableView Footer正在滚动表格 [英] TableView Footer is scrolling with the table

查看:133
本文介绍了TableView Footer正在滚动表格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚在tableView的页脚中实现了加载更多按钮,但页脚始终与表格一起滚动。我的tableView的样式是UITableViewStylePlain。

I just implemented a Load More button into the footer of my tableView, but the footer is always scrolling with the table. The style of my tableView is UITableViewStylePlain.

请你告诉我哪里出错了。

Please could you tell me where I am going wrong.

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    UIView *footerView = nil;
    if(footerView == nil) {
        footerView  = [[[UIView alloc] init] autorelease];
        footerView.backgroundColor = [UIColor clearColor];
        UIButton *button = [[UIButton alloc] init];    
        button.layer.cornerRadius = 7;
        [button setFrame:CGRectMake(10, 3, 300, 44)];
        [button setTitle:@"Load 20 more" forState:UIControlStateNormal];
        [button.titleLabel setFont:[UIFont boldSystemFontOfSize:20]];
        [button setBackgroundColor:[UIColor whiteColor]];
        [button.titleLabel setTextColor:[UIColor blackColor]];
        [button addTarget:self action:@selector(load20More) forControlEvents:UIControlEventTouchUpInside];
        [footerView addSubview:button];
        [button release];
    }
    if ([songInfo count] > 20 && count < 100) {
        return footerView;
    }
    else
        return nil;
}


推荐答案

首先, tableView:viewForFooterInSection 没有为表定义页脚,它为表中的部分定义了页脚。您可以在一个表中包含多个部分页脚。如果您的表只是一个部分,使用此方法将在功能上等同于添加表页脚,但它不应该是表的页脚。如果这是您想要的,那么使用实际的表页脚是更好的做法,这可以通过简单地将视图分配给 UITableView 来实现。 tableFooterView property。

First of all, tableView:viewForFooterInSection does not define a footer for the table, it defines a footer for the section in the table. You can have multiple section footers in one table. In the case where your table is only one section, using this method will be functionally equivalent to adding a table footer, but it is NOT meant to be the table's footer. It is much better practice to use the actual table footer if that's what you want, which can be accomplished by simply assigning a view to the UITableView's tableFooterView property.

但是,表格页脚(部分页脚和表格页脚)都可以与您的表格一起滚动。如果你想要实现一个粘贴在屏幕底部并且不会随桌面滚动的页脚,最好的办法是调整你的 UITableView 小尺寸来制作你的页脚的空间,并添加一个新视图坐在你刚刚清除它的位置。这样,它就会固定到位,表格中的可滚动区域不会与页脚重叠。

However, table footers (section footers AND table footers) are both built to scroll with your table. If you are looking to implement a "footer" that sticks to the bottom of the screen and does not scroll with the table, your best bet is to resize your UITableView smaller to make room for your "footer", and add a new view to sit in the spot you just cleared for it. That way, it will stick in place, and the scrollable region in your table will not overlap with the "footer".

这篇关于TableView Footer正在滚动表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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