1
我有一個容器視圖:表視圖中消失時,我添加約束
和我有我添加到容器編程表視圖:
self.searchResultsSourcesTVC = [storyboard instantiateViewControllerWithIdentifier:@"searchResultsSourcesTVC"];
[self.searchResultsContainer addSubview:self.searchResultsSourcesTVC.view];
結果這裏是表格視圖不會自動調整大小以適應容器;它似乎向屏幕南部延伸了很長一段時間,以至於滾動條可以完全消失在屏幕以南。但它確實顯示錶格和搜索結果。
所以我嘗試添加約束(我使用的自動佈局),使表視圖的垂直邊界匹配的容器觀點:
UITableView *tableView = self.searchResultsSourcesTVC.tableView;
NSDictionary *views = NSDictionaryOfVariableBindings(tableView);
tableView.translatesAutoresizingMaskIntoConstraints = NO; // without this line there are conflicts
[self.searchResultsContainer addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[tableView]|" options:0 metrics:Nil views:views]];
[self.view layoutIfNeeded]; // not sure whether this line is necessary
現在有沒有表都沒有。只是一個空白的觀點。
我在做什麼錯?什麼是以編程方式向容器視圖添加表視圖的最佳方式,並使表視圖的邊界與容器視圖的邊界一致?謝謝
創建的左/右側的約束太多,然後看看會發生什麼...... – tarmes