I am getting this error from my custom UITableViewHeaderFooterView
:
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Auto Layout still required after executing -layoutSubviews. WYBDetailHeaderView's implementation of -layoutSubviews needs to call super.'
I have subclassed UITableViewHeaderFooterView
and created a XIB file which I load using registerNib:forHeaderFooterViewReuseIdentifier:
on my UITableView
.
As there is no UITableViewHeaderFooterView
in IB, I have followed the advice in other posts and just used UIView
( UITableViewHeaderFooterView in InterfaceBuilder ; UITableViewHeaderFooterView with IB ).
My custom UITableViewHeaderFooterView
uses AutoLayout and includes two multi-line UILabel
's, and I assume the problem is related to the fact that these subviews are on the UITableViewHeaderFooterView
itself and not .contentView
. However I do not know how to do that using IB.
This is my layoutSubviews
implementation (I've tried a few combinations without success). I even get the error when I remove this function altogether:
- (void)layoutSubviews
{
[super layoutSubviews];
// Commented out because of infinite loop.
// If this was a custom UITableViewCell I would call these methods on self.contentView
//[self setNeedsLayout];
//[self layoutIfNeeded];
self.titleLabel.preferredMaxLayoutWidth = CGRectGetWidth(self.titleLabel.frame);
self.subtitleLabel.preferredMaxLayoutWidth = CGRectGetWidth(self.subtitleLabel.frame);
}
How should I be doing this?
Try this method :
-(UIView*) tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
Then, load xib file in it.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.