UITableView display of the area head (plain style area head suspension display; grouped style the area header follows table sliding)

Source: Internet
Author: User

Plain style area head suspension display; grouped style area head follow table slide

Code:


#import "ViewController.h"


@interface Viewcontroller () <UITableViewDelegate,UITableViewDataSource>

@property (Nonatomic,strong) UITableView *tab;

@end


@implementation Viewcontroller


-(void) Viewdidload {

[Superviewdidload];

Do no additional setup after loading the view, typically from a nib.

UITableView *tab = [[Uitableviewalloc]initwithframe:self.view.boundsstyle:uitableviewstyleplain];

[Self.viewaddSubview:tab];

Tab.delegate =self;

Tab.datasource =self;

[Tab registerclass:[uitableviewcellclass]forcellreuseidentifier:@ "Cell"];

self.tab = tab;

}


-(Nsinteger) Numberofsectionsintableview: (UITableView *) tableview{

RETURN4;

}


-(Nsinteger) TableView: (UITableView *) TableView numberofrowsinsection: (Nsinteger) section{

RETURN10;

}


-(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) indexPath{

UITableViewCell *cell = [tableviewdequeuereusablecellwithidentifier:@ "cell"];

Cell.textLabel.text = [nsstringstringwithformat:@ partition:%ld___ rows:%ld, Indexpath.section,indexpath.row];

return cell;

}

-(CGFloat) TableView: (UITableView *) TableView Heightforrowatindexpath: (Nsindexpath *) indexpath{

Return40;

}

-(CGFloat) TableView: (UITableView *) TableView heightforheaderinsection: (Nsinteger) section{

Return30;

}


-(UIView *) TableView: (UITableView *) TableView viewforheaderinsection: (Nsinteger) section{

UIView *aview = [[Uiviewalloc]initwithframe:cgrectmake (0,0, [uiscreenmainscreen].bounds.size.width,30]];

Aview.backgroundcolor = [Uicoloryellowcolor];

return aview;

}





-(void) didreceivememorywarning {

[Superdidreceivememorywarning];

Dispose of any of the can is recreated.

}



@end

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.