How to dynamically set the height of the UITableView tableheader in AutoLayout mode

Source: Internet
Author: User

A recent problem is the use of a separate xib file AutoLayout to create a UITableView tableheader. This xib is a dynamic-height view.


So there is a problem, the view created with Xib is fixed height, if used directly:

M_contenttableview.tableheaderview= Headerview;

Such a statement to set Headerview, then the Headerview will always be a fixed height, if the content is too large to display incomplete, if the content is too small, then left a blank.


Tried the Headview internally with a variable m_bneedheight to record the height of the headerview inside the actual need, and then at each time this

M_bneedheight, modify the Headerview Frame outside, the code is as follows:

-(void) onneedsheightchanged: (cgfloat) nneedsheight

{

Circledetailsheaderview * Headerview = [self getheaderview];

if (Headerview)

{

CGRect frame = headerview.frame;

Frame.size.height = Nneedsheight;

Headerview.frame = frame;

}

}

This is good, haha, run, found the egg, which is not a bird.


What's the problem?

Finding the following is the ultimate problem-solving code:

-(void) onneedsheightchanged: (cgfloat) nneedsheight

{

Circledetailsheaderview * Headerview = [self getheaderview];

if (Headerview)

{

CGRect frame = headerview.frame;

Frame.size.height = Nneedsheight;

Headerview.frame = frame;

M_contenttableview.tableheaderview = Headerview;

}

That is, not only to reset the frame, but also to re-assign the value to TableView, so that TableView will go to the layout of the outside to assign the value of the past Headerview position and size.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.