Can't set constraints of UItableView's tab

2019-04-09 11:56发布

问题:

I want the screen only shows one tableveiwCell with headerView.I added a UIView as header view on the top of UITableView with "Size classes" in storyboard(Just drag a UIView on the top of the UITableView), it can compatible with all devices screen size in this way.

So change header view's height by constraints is what i want to. but when i try to do that, i cant set constraints for the headerView(Xocde doesn't enable me select any constrains in storyboard, Image 2 below). As below.

Any ideas, thanks!

The project code is here: https://github.com/williamhqs/AutoLayoutTableViewHeaderView

EIDT: Seems it still can't be set in storyboard.

Then i will have to change table header view's frame by code then update constraints.

UIView *v = self.tableView.tableHeaderView;
CGRect fr = v.frame;
fr.size.height = [UIScreen mainScreen].bounds.size.height -100;
v.frame = fr;
[self.tableView updateConstraintsIfNeeded];

回答1:

i think that UIView doesn't have any superview So that it is not showing the constraints for view.



回答2:

Then i will have to change table header view's frame by code then update constraints.

UIView *v = self.tableView.tableHeaderView;
CGRect fr = v.frame;
fr.size.height = [UIScreen mainScreen].bounds.size.height -100;
v.frame = fr;
[self.tableView updateConstraintsIfNeeded];