Odkąd odkryłem, AutoLayoutże używam go wszędzie, teraz próbuję go używać z rozszerzeniem tableHeaderView.
Zrobiłem subclassz UIViewdodatkiem wszystkiego (etykiety itp ...) Chciałem z ich ograniczeniami, a następnie dodałem to CustomViewdo UITableView" tableHeaderView.
Wszystko działa dobrze z wyjątkiem UITableViewzawsze wyświetla powyższychCustomView przez wyżej mam na myśli CustomViewto podUITableView więc nie widać!
Wydaje się, że bez względu na to, co robię, heightz UITableView' tableHeaderViewjest zawsze 0 (tak samo jak szerokość, x i y).
Moje pytanie: czy w ogóle da się to zrobić bez ręcznego ustawiania ramy ?
EDIT:CustomView ' subviewże używam ma następujące ograniczenia:
_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]]]];
Używam przydatnej biblioteki „KeepLayout”, ponieważ ręczne pisanie ograniczeń zajmuje wieczność i zbyt wiele wierszy dla jednego ograniczenia, ale metody nie wymagają wyjaśnień.
I UITableViewma te ograniczenia:
_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;
Nie wiem, czy muszę ustawiać pewne ograniczenia bezpośrednio na CustomView, myślę, że wysokość CustomView jest określana przez ograniczenia zawarte w UILabel„tytule”.
EDYCJA 2: Po kolejnym dochodzeniu wydaje się, że wysokość i szerokość CustomView są poprawnie obliczone, ale górna część CustomView jest nadal na tym samym poziomie co górna część UITableView i poruszają się razem, gdy przewijam.