【发布时间】:2014-03-12 09:55:03
【问题描述】:
我在使用 UITableView 时遇到了奇怪的行为。我用UITableView 设置了UIViewController。 UITableView 包含一个 tableHeaderView、tableFooterView、一个部分页脚视图和几个具有动态高度的 UITableViewCells。
问题是tableFooterView 出现在表格中间的某处(悬停在单元格上),而不是在表格内容的底部对齐。显然,表格的 contentSize 属性也返回了不正确的内容大小(特别是高度)。
但是,自定义部分页脚视图显示在正确的位置(在实际的 tableFooterView 下方——它悬停在表格中间)。
有什么想法吗?
注意:我的自定义表格视图(使用自动布局进行动态高度处理)显示“不明确的布局:2 个视图在垂直方向不明确”。警告,但它在运行时正确调整大小。
表格设置非常简单:
// 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;
}
【问题讨论】:
标签: ios uitableview autolayout tablefooterview