TableFooterView does not align properly at the bottom of the table

I have strange behavior with UITableView. I installed UIViewControllerwith UITableView. UITableViewIt contains tableHeaderView, tableFooterViewfooter section, and a pair of UITableViewCelldynamic heights.

The problem is that it tableFooterViewappears somewhere in the middle of the table (hangs over the cell), and does not align at the bottom of the contents of the table. Apparently, the table property contentSizealso returns the wrong size of the content (in particular, the height).

However, the footer of the user section is displayed in the right place (and below the actual one tableFooterView- which is in the middle of the table).

Any ideas what is going on?

Note. My custom tabular view (with dynamic bit height using automatic layouts) shows "Ambiguous layout: 2 vertical representations are ambiguous." warning but correct resizing at runtime.

Setting up the table is quite 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;
}
+4
source share
3 answers

In the end, I got an extra section with only a header and footer (and no lines) to get the desired results. Perhaps car dealerships act strangely. I still get "Ambiguous Layout: 2 Views Vertically Ambiguous", but the user interface looks good.

+2
source
+2

Try setting footerView.autoresizingMask = .flexibleWidth

Code example:

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
+1
source

Source: https://habr.com/ru/post/1531300/


All Articles