TableView Footer正在滚动表格

max*_*ax_ 6 iphone objective-c uitableview

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

请你能告诉我哪里出错了.

- (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;
}
Run Code Online (Sandbox Code Playgroud)

the*_*gal 24

首先,tableView:viewForFooterInSection没有为表定义页脚,它为表中的部分定义了页脚.您可以在一个表中包含多个部分页脚.如果您的表只是一个部分,使用此方法将在功能上等同于添加表页脚,但它不应该是表的页脚.这是更好的做法是使用实际的表尾,如果这就是你想要的,这可以通过简单地分配以期实现UITableViewtableFooterView财产.

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