jeudi 25 juin 2015

autolayout constraints in nib not honored for UITableViewHeaderFooterView

I have a UITableView with several columns of data. The reusable cells are loaded from an xib file which has the appropriate labels and autolayout constraints. Everything works perfectly; the table columns are laid out correctly on different devices and when the devices are rotated.

The problem I am having is trying to create a table footer to show the totals of the columns in the table. I created an xib file with the same autolayout constraints as the cell xib file and am loading it in tableView.viewForFooterInSection the same way I did for the cells. As required, I am using a subclass of UITableViewHeaderFooterView instead of UITableViewCell.

The awakeFromNib method in the UITableViewHeaderFooterView subclass sets the background color, so I can see that it is the correct size on all devices/orientation, but the labels from the footer xib file are not getting laid out to match the table cells. The autolayout constraints from the footer xib file are not being honored. When I set a different background color in the footer xib file, the table footer shows this background color for the length of the xib's view.

I'm new to all of this technology and would greatly appreciate help in resolving this incredibly frustrating issue.

Is this a bug in Swift? Is there a way to use autolayout for UITableViewHeaderFooterViews loaded from nibs?

See more ..

Aucun commentaire:

Enregistrer un commentaire