iOS设置tableView.tableHeaderView高度不生效

开发者在使用XIB创建的视图作为tableView.tableHeaderView时遇到frame失效问题,通过将XIB视图添加到代码创建的父视图中解决了问题,表明可能需要针对XIB视图特殊处理布局。
摘要由CSDN通过智能技术生成

今天在开发界面时候遇到个问题,我使用xib创建的视图view

- (FindBrotherView *)brotherView{

    if(!_brotherView){

        _brotherView =[[[NSBundle mainBundle]loadNibNamed:@"FindBrotherView" owner:self options:nil]lastObject];

        _brotherView.frame =CGRectMake(0, 0, Screen_Width, 106);

    }

    return _brotherView;

}

然后我将brotherView 设置为了    self.tableView.tableHeaderView =self.brotherView;

这时候brotherView 的frame不生效,高度直接展示整个屏幕的高度,我在各个地方设置brotherView的高度,都没有效果,我直接懵逼了😳

然后我就自己使用纯代码写了一个view设置,正常,这时候我觉得应该就是因为是xib创建的view的原因导致的,但是如果我以后还想用xib创建的view来设置tableView.tableHeaderView怎么办。

这时候我想到了一个方法,我用代码创建一个view,作为父视图,将brotherView添加到上边,是不是就可以了。

    UIView * fatherView =[[UIView alloc]initWithFrame:CGRectMake(0, 0, Screen_Width, 106)];

    self.brotherView.frame =fatherView.bounds;

    [fatherView addSubview:self.brotherView];

    self.tableView.tableHeaderView =fatherView;

项目运行起来,显示正常,解决问题

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值