UITableView区头区尾约束问题

之前项目碰到这个问题 确实之前的没有碰到这种问题 对了你答对了 百度。。。

测试代码SDK iOS9.2环境 其他的没有试过

我参考了 标哥的这篇博客http://blog.csdn.net/woaifen3344/article/details/50166659

自己也试了确实是可行啊  但是作为一个懒得吃饭都不想张嘴的人 标哥的固然好 但是代码不少哦 却不是我想要的  

我就在想 我直接在返回区尾里面直接设置高度能否实呢?

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

UIView * baseView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 64)];

baseView.backgroundColor = [UIColor blueColor];

return baseView;

}

果然有效 但是却不是我设置的64 !?

查看了下 我同样实现了

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

return 100;

}

难道跟这个有关系?没关系 试试吗

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

return 64;

}

果然不出所料 区尾高度和 这个代理函数设定的是一致的 既然这样的话 看看是不是跟返回的视图都无关呢?

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

UIView * baseView = [[UIView alloc] init];

baseView.backgroundColor = [UIColor blueColor];

return baseView;

}

依然有64pt的蓝色区域 OK!!!不过还是有些问题 我就在

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

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

下了断点 运行结果 是系统首先执行了 - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section;

后执行了- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section;

所以 就猜测 布局会首先在- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section;获取到区尾视图约束高度 然后在

通过- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section;返回哪个一个视图区尾返回视图 并且将获取的约束高度 直接赋值给改视图 


至此到处9.2的表头约束如何进行的


1 约束区头区尾时候 直接在对应返区头区尾返回高度函数中直接写约束高度 

2 在对应返回区头区尾视图中

UIView * view = [UIView new];

return view;即可  view可以是UIView的子类 

仅仅两步就O了是不是很爽呢 

转载于:https://juejin.im/post/5a32957e51882549a7790d02

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值