-systemLayoutSizeFittingSize: returning incorrect height for tableHeaderView under iOS 8

前端 未结 6 1812
旧时难觅i
旧时难觅i 2021-02-07 00:08

There are numerous threads about correctly sizing a tableHeaderView with auto-layout (one such thread) but they tend to pre-date iOS 8.

I have a situation with numerous

6条回答
  •  春和景丽
    2021-02-07 00:49

    Changing your headerview function to the following works for me:

    - (void)rejiggerTableHeaderView
    {
        self.tableView.tableHeaderView = nil;
    
        UIView *header = self.headerView;
        CGRect frame = header.frame;
        frame.size.width = self.tableView.frame.size.width;
        header.frame = frame;
    
        [header setNeedsLayout];
        [header layoutIfNeeded];
    
        CGFloat height = [header systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height;
    
        CGRect headerFrame = header.frame;
        headerFrame.size.height = height;
    
        header.frame = headerFrame;
    
        self.tableView.tableHeaderView = header;
    }
    

提交回复
热议问题