Mus*_*afa 5 uitableview ios autolayout tablefooterview
我遇到了一个奇怪的行为UITableView。我已经设置了UIViewController一个UITableView. UITableView包含一个tableHeaderView,tableFooterView一个节页脚视图,以及几个UITableViewCell具有动态高度的s。
问题是tableFooterView出现在表格中间的某处(悬停在单元格上),而不是在表格内容的底部对齐。显然,表的contentSize属性也返回不正确的内容大小(特别是高度)。
The custom section footer view, however, is appearing in the right place (and below the actual tableFooterView -- which is hovering in the middle of the table).
Any ideas what's going on?
Note: My custom table-view (with dynamic height handing using Auto Layouts) is showing a "Ambiguous Layout: 2 views are vertically ambiguous." warning, but it's resizing correctly at run-time.
The table setup is pretty simple:
// Set table header/footer view
self.myTableView.tableHeaderView = self.myTableHeaderView;
self.mainTableView.tableFooterView = self.myTableFooterView;
// Table delegate methods
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return [self heightForCellAtIndexPath:indexPath];
}
- (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath {
return [MyCustomCell defaultHeight];
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
if (section == 0) {
return self.mySectionFooterView;
}
return [UIView new];
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
if (section == 0) {
return [self heightForSectionFooterView];
}
return 0.01f;
}
Run Code Online (Sandbox Code Playgroud)
我最终使用了一个额外的部分,其中只有页眉和页脚(没有行),以获得所需的结果。也许自动布局表现得很奇怪。我仍然收到“布局不明确:2 个视图在垂直方向上不明确。”,但 UI 看起来不错。