应对可变长度文本的情景,重写viewDidLayoutSubviews方法。
viewDidLayoutSubviews
12345678910
- (void)viewDidLayoutSubviews{ [super viewDidLayoutSubviews]; CGSize size = [_headerView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize]; CGRect headerFrame = _headerView.frame; headerFrame.size = size; _headerView.frame = headerFrame; [_tableView setTableHeaderView:_headerView];}