TableView Style:plain (head title move up will not disappear)
TableView style:grouped (head title move up will disappear)
#import "ViewController.h"#import "CarGroup.h"@interfaceViewcontroller () <UITableViewDataSource>@property (Weak, nonatomic) Iboutlet UITableView*TableView, @property (nonatomic,strong) Nsarray*cargroups;@end@implementationViewcontroller- (void) viewdidload {[Super viewdidload]; //set up a data sourceSelf.tableview.datasource=Self ;}//Hide the status bar-(BOOL) prefersstatusbarhidden{returnYES;}-(Nsarray *) cargroups{if(_cargroups==Nil) { //Initialize//brand of the German departmentCargroup *car1=[[Cargroup alloc]init]; Car1.title=@"brand of the German department"; Car1.desc=@"The brand of the German department is very good"; Car1.cars[Email protected] [@"Audi",@"BMW",@"Mercedes",]; //Japanese BrandsCargroup *car2=[[Cargroup alloc]init]; Car2.title=@"Japanese Brands"; Car2.desc=@"Japanese brand is very good sssss"; Car2.cars[Email protected] [@"Honda",@"Toyota"]; //European BrandsCargroup *car3=[[Cargroup alloc]init]; Car3.title=@"European Brands"; Car3.desc=@"The European brand is very good yyyyyy"; Car3.cars[Email protected] [@"Flushing Force",@"Lamborghini",]; [Email protected] [CAR1,CAR2,CAR3]; } return_cargroups;}/** How many sets of data are there?*/-(Nsinteger) Numberofsectionsintableview: (UITableView *) tableview{returnSelf.carGroups.count;}/** How many lines are there in section group*/-(Nsinteger) TableView: (UITableView *) TableView numberofrowsinsection: (nsinteger) section{//get the model corresponding to section classCargroup *cg=Self.cargroups[section]; returnCg.cars.count;}/** What is displayed in each row (cell)*/-(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) indexpath{//UITableViewCell *cell=[[uitableviewcell Alloc]initwithstyle:uitableviewcellstyledefault ReuseIdentifier:nil] ;UITableViewCell*cell=[[UITableViewCell alloc] Initwithstyle:uitableviewcellstyledefault Reuseidentifier:nil]; //Take out model indexpath.section group corresponding to modelCargroup *cg=Self.cargroups[indexpath.section]; //the name of the brand to pick up the first indexpath.row.NSString *car=Cg.cars[indexpath.row]; //set the text displayed by the cellcell.textlabel.text=car; returncell;}/** What header headings are shown in section group*/-(NSString *) TableView: (UITableView *) TableView titleforheaderinsection: (nsinteger) section{Cargroup*cg=Self.cargroups[section]; returnCg.title;}/** Section group shows what the trailing title*/-(NSString *) TableView: (UITableView *) TableView titleforfooterinsection: (nsinteger) section{Cargroup*cg=Self.cargroups[section]; returnCg.desc;}
Basic use of IOS TableView