"IOS" TableView Footerview does not stay on the bottom of the TableView with cell scrolling

Source: Internet
Author: User


The Apple method provides me with TableView Footerview and Headerview to stay at the top of the very good effect, sometimes we do not need these footerview and Headerview stay at the bottom or the upper, now take Footerview as an example, Tell me about the solution I'm developing: (at present two kinds of)


The first method is to set the TableView style to Uitableviewstyleplain when initializing TableView, while overriding the TableView scrollviewdidscroll: (Uiscrollview *) ScrollView

specific The code is as follows:

<span style= "FONT-SIZE:14PX;" >uitableview *tableview = [[UITableView alloc] Initwithframe:cgrectmake (0, 0, Self.view.frame.size.width, Self.view.frame.size.height) style:uitableviewstyleplain];</span>

<span style= "FONT-SIZE:14PX;" >-(void) Scrollviewdidscroll: (Uiscrollview *) scrollview{        cgfloat sectionheaderheight = 10;//Set you footer height    if (scrollview.contentoffset.y<=sectionheaderheight&&scrollview.contentoffset.y>=0) {        Scrollview.contentinset = Uiedgeinsetsmake (-scrollview.contentoffset.y, 0, 0, 0);    } else if (scrollview.contentoffset.y>=sectionheaderheight) {        Scrollview.contentinset = Uiedgeinsetsmake (- Sectionheaderheight, 0, 0, 0);    }    } </span>

The second method: when initializing the TableView , set the TableView style to uitableviewstylegrouped, at the same time, in the UITableView proxy method, set the height of the footerview to a very small (no visible void) value, just fine! (note here, can not be set to 0, no tableview will think you do not set the height will take the default height)

Specific code:

<span style= "FONT-SIZE:14PX;" >uitableview *tableview = [[UITableView alloc] Initwithframe:cgrectmake (0, 0, Self.view.frame.size.width, self.view.frame.size.height) style:uitableviewstylegrouped];    Tableview.delegate = self;    Tableview.datasource = self;</span>

-(CGFloat) TableView: (UITableView *) TableView heightforheaderinsection: (nsinteger) section{    return 0.0001f;}



Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

"IOS" TableView Footerview does not stay on the bottom of the TableView with cell scrolling

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.