The holes in the Tableheaderview of iOS development

Source: Internet
Author: User
Tags reserved
Preface:

TableView has a property called Tableheaderview with it we can do a lot of things in TableView's head plus a custom view with TableView scrolling along with

It's usually a carousel, like this dad90de4-84e9-4194-9554-40956ad01e32.png

There are two ways to create the tableheaderview of TableView, one is the code creation, the other is creating with the Xib with the code

  UIView *header = [[UIView alloc] Initwithframe:cgrectmake (0, 0, self.view.width, MB)];
    Set header
  Self.tableView.tableHeaderView = header;
Because there is no way to set the height of the Self.tableView.tableHeaderView, you must set the height of the custom view to set the height of the Self.tableView.tableHeaderView Create with Xib
Bbstableheaderview * cell = [Bbstableheaderview Tableheaderview];
cell = 291;
Self.tableView.tableHeaderView = header;
This setup is certainly not a problem, but this time you set the height is inaccurate and there is no way to fit the model, so the settings are not available, and then there is a small tips is very simple but if you do not think that you may be in the height of the issue of debugging all day for example, I -Solutions
    UIView * Header = [[UIView alloc]init];
    Header.backgroundcolor = [Uicolor whitecolor];
    Bbstableheaderview * cell = [Bbstableheaderview Tableheaderview];
    Cell.backgroundcolor = [Uicolor clearcolor];
    [Header Addsubview:cell];
    Header.height = 291;
    Self.tableView.tableHeaderView = header;
The principle is to add a layer of view below xib view (code created) to ensure that you set the height is accurate because xib highly accurate must add a layer of code to create a view to ensure that your view height is accurate and suitable for various models of otherThe top of the TableView will become blank due to the setting of Tableheaderview

The solution is as follows:

Inside the controller viewdidload write this code should be able to

self.automaticallyadjustsscrollviewinsets = NO;
* * Coordinates: In the upper-left corner of the screen as the origin (iOS7 before the status bar or under the navigation bar)
2.UIScrollView (including its subclasses, such as UITableView): will automatically reserve some white space at the top and bottom (because scrolling through the translucent navigation bar or under the Tabbar, you need to be able to see the effect), whether or not to reserve the blank can be uiviewcontroller by the
This property is controlled by the automaticallyadjustsscrollviewinsets (the default Yes, which indicates that whitespace is reserved).
as long as you use iOS to develop, you can find.

a controller that appears Uiscrollview (including its subclasses) must be the first view to be added to the controller to reserve whitespace, the first of which is relative to all child views, not just to other uiscrollview (including its subclasses).
 
So how do I solve the problem, or is this attribute automaticallyadjustsscrollviewinsets, look at its documentation, it says, if more than two uiscrollview (including its subclasses) appear in a controller , this property needs to be set to No. No whitespace is reserved, so all uiscrollview (including its subclasses) in this controller need to reset the coordinates.

Sometimes the above method setting is useless, so if the above method is not used, it is probably the grouping style used to create the TableView.
The workaround is as follows
Note: Do not write 0 to write a relatively small number don't ask why because setting 0 has no effect
-(CGFloat) TableView: (UITableView *) TableView heightforfooterinsection: (nsinteger) section
{return
    0.01;
}

-(CGFloat) TableView: (UITableView *) TableView heightforheaderinsection: (nsinteger) Section
{
    return 0.01;
}
If you have other needs like how to hide self.tableView.tableHeaderView or how to change the height of a self.tableView.tableHeaderView look below
Display Headerview
[Self.tableView.tableHeaderView sethidden:no];

Hide Headerview
 [Self.tableView.tableHeaderView Sethidden:yes];
This setting is no use don't believe you can try always for 0
self.tableView.tableHeaderView.height = xxx;

Should be so set
uiview *tableheaderview = _tableview.tableheaderview;
Tableheaderview.height = 0.01;
[_tableview Settableheaderview:tableheaderview];
If you want to set
Tableheaderview.height = 0;//This is not effective and the top of the TableView will be more than  one blank must be set a relatively small value of course, this value is not 0;


Related Article

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.