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

Source: Internet
Author: User


Apple officially gave me 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, Talk about the solution I'm developing: (two at the moment)


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

Detail the code is as follows:

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

-(void) Scrollviewdidscroll: (Uiscrollview *) scrollview{        cgfloat sectionheaderheight = 10;//Set your 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>

Another way: when initializing TableView , set the TableView style to uitableviewstylegrouped, at the same time in the UITableView proxy method, the height of the Footerview is set to a small (without leaving visible gaps) of the 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)

Detailed code:

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;}



"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.