tableview设置footer会悬停在屏幕下方

最近项目中需要给UITableView设置一个类似于“已经到底部啦”的footview提醒,想都不想直接用代理方法

 (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section

自定义一个view返回给这个代理方法,然后实现另一个方法

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section

设置了footerview的高度,满心欢喜的跑项目,发现并不是我想要的,我想要的是footerview跟随着cell的滑动而滑动,当数据超过一屏幕时候,需要不显示,等滑动到底部的时候再显示出来。

网上各种说滑动的时候重新设置frame的方法,从内心里比较抵触这样做。。。

最后还是想到一个方式来解决这个问题,既然我不能直接用系统的footerview,那么我定义两个section总可以了吧,然后,返回tableview的section的时候返回2,在cellForRowAtIndexPath方法里先判断是哪个section,如果section是要显示footerview的那个分组时,返回一个之前定义好的view给它。然后运行程序,结果如预期一样

部分代码:

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 2;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if(indexPath.section==0)
        return 25+25+15+120;
    else
        return 40;
    
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if(section == 1)//footer
        return 1;
    
    if(tableView == self.courseListTableView){//待开始
        if(self.courseListDataArray.count == 0){
            [LCSPlaceholderView showOnView:tableView type:LCSPlaceholderViewType_Course withTapBlock:^{
                NSLog(@"无课程");
            }];
        }else{
            [LCSPlaceholderView removeFromSuperView:tableView];
        }
        return self.courseListDataArray.count;
    }else{//已完成
        if(self.courseFinishDataArray.count == 0){
            [LCSPlaceholderView showOnView:tableView type:LCSPlaceholderViewType_Course withTapBlock:^{
                NSLog(@"无课程");
            }];
        }else{
            [LCSPlaceholderView removeFromSuperView:tableView];
        }
        return self.courseFinishDataArray.count;
    }

 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if(indexPath.section == 1){
        UITableViewCell *cell = [[UITableViewCell alloc] init];
        LCSCustomTableFooterView *footerView = [[LCSCustomTableFooterView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 40)];
        
        [cell.contentView addSubview:footerView];
        return cell;
    }
    
    static NSString *cellReuseID = @"cellReuseID";

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值