关于tableView的footView对tableview的frame.height的高度调配

 有的时候,我们创建的tableView会不确定它的frame,里面的cell不够多的话,就会产生这种情况。

















我们要怎么解决呢。想了好久,想到以前看到的为什么要添加一个尾部视图,就是footView,于是尝试着添加进去,然后出现了自己想要的结果。 















这真是太意外了,原来tableViewtableView有这个作用。

仔细想了一下。我们可以一开始就定义tableViewframe,让它的高度设置为我们让它可以达到的最大的高度。

然后添加一个footView,就可以达到即使cell不够多,我们的tableView也不会显示一大串的空白cell来填充tableView的其他frame的空白部分。

我把部分代码复制出来:


#pragma mark createTableView

-(void)createTableView{

    _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight-20-44)];

    _tableView.dataSource = self;

    _tableView.delegate = self;

   _tableView.separatorInset = UIEdgeInsetsMake(0, 0, 0, 0);

    _tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLineEtched;

    

    [self.view addSubview:_tableView];

}


#pragma mark tableView代理方法

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

    return 50;

}

- (nullable UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{

    SMEndView * endView = [[SMEndView alloc]init];

    endView.frame = CGRectMake(0, 0, ScreenWidth, 50);

    return endView;

}





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值