The section of IOS 7 viewforheaderinsection starts at 1 instead of 0

Source: Internet
Author: User

Problem

(UIView *) TableView: (uitableview *) TableView viewforheaderinsection: (nsinteger) Section The section in the method appears to start at 1 instead of from 0



Ideas

Although the program is set up Self . TableView. Sectionheaderheight =20

It's still not working. The section in Viewforheaderinsection always starts at 1.

So I found that if you use the method:

-(cgfloat) TableView: (uitableview *) TableView heightforheaderinsection: (nsinteger) Section

{

return ;

}

It's starting from 0.

Nima Jing A new feature of IOS7, in fact self. TableView. Sectionheaderheight =20 This efficiency is much faster than the method. If there are no special needs, let's set the properties directly.

-(CGFloat) TableView: (UITableView *) TableView heightforheaderinsection: (nsinteger) section{return  +;}-(UIView *) TableView: (UITableView *) TableView viewforheaderinsection: (nsinteger) section{UIView*headerview = [[UIView alloc] Initwithframe:cgrectmake (0,0, TableView.frame.size.width, +)]; UILabel*label = [[UILabel alloc] Initwithframe:cgrectmake ( -,Ten, TableView.frame.size.width, -)]; Label.font= [Uifont systemfontofsize:16.0f];//font size of UilabelLabel.numberoflines =0;//This property must be defined, otherwise uilabel will not wrap.Label.textcolor = Cr_rgbcolor ( the, the, the); Label.textalignment= Nstextalignmentleft;//Text Alignment[Label Setbackgroundcolor:[uicolor Clearcolor]; Label.text=Self.sectiontitles[section];    [Headerview Setbackgroundcolor:[uicolor Clearcolor];    [Headerview Addsubview:label]; returnHeaderview;}-(UIView *) TableView: (UITableView *) TableView viewforfooterinsection: (nsinteger) section{return[[Crcustomfooter alloc] init];}- (void) TableView: (UITableView *) TableView Didselectrowatindexpath: (Nsindexpath *) indexpath{nsuinteger section=indexpath.section; Nsuinteger Row=Indexpath.row; if(Section = =1){        if(Row = =0) {[Self recommendtofriends];        [TableView Deselectrowatindexpath:indexpath Animated:yes]; }Else if(Row = =1) {[Self sendfeedback];        [TableView Deselectrowatindexpath:indexpath Animated:yes]; }Else if(Row = =2) {[Self rateapp];        [TableView Deselectrowatindexpath:indexpath Animated:yes]; }Else{        }    }}

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.