tableView设置UITableViewStyleGrouped顶部有空余高度

一,概述

     tableView是我们在IOS开发中经常使用到一种可视控件,tableView的类型大致分为两种:UITableViewStyleGrouped和 UITableViewStylePlain.  tableView的默认的类型是UITableViewStylePlain.

二,UITableViewStyleGrouped 和UITableViewStylePlain 两者的区别

   1>UITableViewStylePlain 

       1)有多段时(区头,区尾), 段头停留(自带粘性效果)

       2)没有中间的间距和头部间距(要想有的重写UITableViewCell \UITableViewHeaderFooterView里面的setFrame方法)   

扩展让段头不停留(取消粘性效果)

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
      CGFloat sectionHeaderHeight = 30;
      if (scrollView.contentOffset.y<=sectionHeaderHeight&&scrollView.contentOffset.y>=0) {
           scrollView.contentInset = UIEdgeInsetsMake(-scrollView.contentOffset.y, 0, 0, 0);
         } else if (scrollView.contentOffset.y>=sectionHeaderHeight) {
           scrollView.contentInset = UIEdgeInsetsMake(-sectionHeaderHeight, 0, 0, 0);
    }
}

   2>UITableViewStyleGroup
      在tableview的代理方法:返回组的头/尾视图中设置具体高度时,开头结尾总是默认有一段距离,并且如果设置她们中的某个距离为0,则无效。
      正确的处理方法

   1)设置标头的高度为特小值 (不能为零 为零的话苹果会取默认值就无法消除头部间距了)

   UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 0.001)];
   view.backgroundColor = [UIColor redColor];
   self.tableView.tableHeaderView = view;
   2)写代理方法(中间的留白其实是段尾的高度 代理的作用设置段尾的高度 返回值也不能为0(设置为0 在ios看来等于未设置))
   -(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
        return 0.01f; 
       或者
       return CGFLOAT_MIN;
    }

拓展:特殊的处理方法实现该效果
     1. self.tableView.contentInset = UIEdgeInsetsMake(-44, 0, 0, 0);
     2.重写UITableViewHeaderFooterView的
    

    -(void)setFrame:(CGRect)frame{
       frame.size.height+=10;
       [super setFrame:frame];
    }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值