应对可变长度文本的情景,重写viewDidLayoutSubviews方法。

1
2
3
4
5
6
7
8
9
10
- (void)viewDidLayoutSubviews
{
[super viewDidLayoutSubviews];

CGSize size = [_headerView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize];
CGRect headerFrame = _headerView.frame;
headerFrame.size = size;
_headerView.frame = headerFrame;
[_tableView setTableHeaderView:_headerView];
}