之前项目碰到这个问题 确实之前的没有碰到这种问题 对了你答对了 百度。。。
测试代码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了是不是很爽呢