I'm experiencing a strange behavior with UITableView
. I've setup a UIViewController
with a UITableView
. UITableView
contains a tableHeaderView
, tableFooterView
, a section footer view, and a couple of UITableViewCell
s with dynamic heights.
The problem is that the tableFooterView
appears somewhere in the middle of the table (hovering over the cell), instead of aligning itself at the bottom of the table's content. Apparently, table's contentSize
property is also returning incorrect content size (specifically the height).
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;
}
Try to set footerView.autoresizingMask = .flexibleWidth
Example code:
let footerView = Bundle.main.loadNibNamed(String(describing: MyFooterView.self), owner: nil, options: nil)?.first as! MyFooterView
footerView.frame = CGRect(origin: .zero, size: CGSize(width: view.bounds.width, height: 80))
footerView.autoresizingMask = .flexibleWidth
tableView.tableFooterView = footerView
Looks like for now estimatedHeightForRowAtIndexPath: messes with footer views:
https://twitter.com/steipete/status/420538600384888832
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With