Basic use of IOS TableView

Source: Internet
Author: User

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

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.