Desde que descobri AutoLayoutque o uso em todos os lugares, agora estou tentando usá-lo com umtableHeaderView .
Eu fiz uma subclassde UIViewtudo adicionado (etiquetas etc ...) eu queria com suas limitações, então eu adicionei este CustomViewao UITableView'tableHeaderView .
Tudo funciona bem, exceto o UITableViewsempre exibido acima do CustomView, acima, quero dizer que CustomViewestá abaixo doUITableView por isso não pode ser visto!
Parece que não importa o que eu faça, o heightde UITableView' tableHeaderViewé sempre 0 (assim como a largura, x e y).
Minha pergunta: é possível fazer isso sem definir o quadro manualmente ?
EDIT:
O CustomView' subviewque estou usando tem estas restrições:
_title = [[UILabel alloc]init];
_title.text = @"Title";
[self addSubview:_title];
[_title keep:[KeepTopInset rules:@[[KeepEqual must:5]]]]; // title has to stay at least 5 away from the supperview Top
[_title keep:[KeepRightInset rules:@[[KeepMin must:5]]]];
[_title keep:[KeepLeftInset rules:@[[KeepMin must:5]]]];
[_title keep:[KeepBottomInset rules:@[[KeepMin must:5]]]];
Estou usando uma biblioteca útil 'KeepLayout' porque escrever restrições manualmente leva uma eternidade e muitas linhas para uma única restrição, mas os métodos são autoexplicativos.
E o UITableViewtem estas restrições:
_tableView = [[UITableView alloc]init];
_tableView.translatesAutoresizingMaskIntoConstraints = NO;
_tableView.delegate = self;
_tableView.dataSource = self;
_tableView.backgroundColor = [UIColor clearColor];
[self.view addSubview:_tableView];
[_tableView keep:[KeepTopInset rules:@[[KeepEqual must:0]]]];// These 4 constraints make the UITableView stays 0 away from the superview top left right and bottom.
[_tableView keep:[KeepLeftInset rules:@[[KeepEqual must:0]]]];
[_tableView keep:[KeepRightInset rules:@[[KeepEqual must:0]]]];
[_tableView keep:[KeepBottomInset rules:@[[KeepEqual must:0]]]];
_detailsView = [[CustomView alloc]init];
_tableView.tableHeaderView = _detailsView;
Não sei se tenho que definir algumas restrições diretamente no CustomView, acho que a altura do CustomView é determinada pelas restrições no UILabel"título" nele.
EDIT 2: Após outra investigação, parece que a altura e a largura do CustomView estão calculadas corretamente, mas o topo do CustomView ainda está no mesmo nível que o topo do UITableView e eles se movem juntos quando eu rolar.