美文网首页
2018-08-29 UITableViewStyleGrou

2018-08-29 UITableViewStyleGrou

作者: 惊蛰_e3ce | 来源:发表于2018-08-29 16:02 被阅读0次

    第一个问题:UITableViewStyleGrouped 底部20间距 没找到原因只能设置contentInset了

    - (void)viewDidLoad {
        [super viewDidLoad];
        // Do any additional setup after loading the view, typically from a nib.
        _tableView = [[UITableView alloc]initWithFrame:self.view.frame style:UITableViewStyleGrouped];
        _tableView.tableHeaderView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, CGFLOAT_MIN)];
        _tableView.tableFooterView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, CGFLOAT_MIN)];
        [self.view addSubview:_tableView];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.backgroundColor = [UIColor greenColor];
    //    _tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
        
    //    _tableView.contentInset = UIEdgeInsetsMake(0, 0, -20, 0);
         self.automaticallyAdjustsScrollViewInsets = NO;
    }
    
    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
        return 25;
    }
    - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
        return CGFLOAT_MIN;
    }
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
        if (!cell) {
            cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
    
            cell.backgroundColor = [UIColor redColor];
        }
        cell.detailTextLabel.text = [NSString stringWithFormat:@"%ld",indexPath.row];
        return cell;
    }
    - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
        return 50;
    }
    - (void)didReceiveMemoryWarning {
        [super didReceiveMemoryWarning];
        // Dispose of any resources that can be recreated.
    }   
    

    第二个问题 masonry groupstyle设置表头时会出现大概30左右间距

    先添加到tableview上 在layoutifneed获取到表头的具体frame 在设置表头
    原理是直接设置frame没类似问题

    1:当 屏幕快照 2018-08-09 10.34.49.png

    当tableviewHeader是用frame有确定的宽高时 间距是不存在的
    _tableView = [[UITableView alloc]initWithFrame:self.view.frame style:UITableViewStyleGrouped];

    [self.view addSubview:_tableView];
    [_tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(self.view);
    }];
    

    UIView *tabHeader = [UIView new];
    tabHeader.frame = CGRectMake(0, 0, 320, 100);
    tabHeader.backgroundColor = [UIColor greenColor];
    _tableView.tableHeaderView = tabHeader;
    _tableView.delegate = _adapterManager;
    _tableView.dataSource = _adapterManager;

    屏幕快照 2018-08-09 10.39.47.png

    --------基于此作如下处理:

    UIView *tabHeader = [UIView new];
    tabHeader.backgroundColor = [UIColor greenColor];
    [_tableView addSubview:tabHeader];
    [self.view layoutIfNeeded];
    [tabHeader mas_makeConstraints:^(MASConstraintMaker *make) {
    make.left.right.top.width.mas_equalTo(_tableView);
    make.height.mas_equalTo(_cubeHeadView.frame.size.height);
    }];
    [self.view layoutIfNeeded];
    _tableView.tableHeaderView = tabHeader;

    tabHeader是按照cubeHeadView的高度来的

    目的是在设置 ( _tableView.tableHeaderView = tabHeader;)之前
    获取tabHeader确定的宽高位置

    第三个问题 masonry下 tableview内部在嵌套tableview时 被嵌套的contentsize不准确可能和默认高度(44)有关系

    第四个问题 tableview UITableViewStyleGrouped时顶部可能出现35间距 如不需tableHeaderView 可做如下处理:

        _tableView.tableHeaderView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, QNJWIDTHSCREEN, CGFLOAT_MIN)];
    

    不可改为CGRectZero

    相关文章

      网友评论

          本文标题:2018-08-29 UITableViewStyleGrou

          本文链接:https://www.haomeiwen.com/subject/pokkwftx.html