UITableView: Change the height of Tableheaderview

Source: Internet
Author: User

There is a need to show some different data at the top of the list, and this kind of data needs to be shown by a different View, which is UITableView's tableheaderview.

If the content in the Tableheaderview is fixed, the height should not change with the content, so it is OK.

If the height needs to be changed dynamically, some people (like me) may encounter a problem like this:

I have set the value of each sub-view in the view, the height has been calculated, the frame has been reset, but the height of the Tableheaderview is still the height of the previous, no change. Content becomes more, there will be a part of the invisible, the content is less, there is a part of the blank, put there is really not good.

What to do??

View as TableView Tableheaderview, simply change the frame of the view is useless, TableView will not be generous to the moment to adapt to its height (after Apple will not change it does not know), so, how to tell Tablevi EW, has its tableheaderview changed? Very simple, just a word (the last sentence):

The bounds of the headbgview in advance of obtaining restraint
[Self.headbgview Setneedslayout];
[Self.headbgview layoutifneeded];

CGRect Newframe == newFrame.size.height += newframe;[ Self.tableview Settableheaderview:headerview];

After that, the effect comes out. But this excessive seems a bit stiff, can add a little animation, let it become more pleasing to the eye? Try the following code:

[Self.tableview beginupdates]; [Self.tableview Settableheaderview:headerview]; [Self.tableview endupdates];

UITableView: Change the height of Tableheaderview

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.